From b1d99a744b6473d539abddf2e0ee39e0051535eb Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 16 Mar 2016 09:48:25 +1000 Subject: [PATCH] Standardize the error on device open failures No reason for the drivers to have their own printf each, just return the negative errno and let the common code print it. This now also means that we only return -ENODEV on something that's not really an error, for anything else we print the strerror. Signed-off-by: Peter Hutterer --- src/driver-etekcity.c | 9 ++------- src/driver-hidpp10.c | 10 +--------- src/driver-hidpp20.c | 9 +-------- src/driver-roccat.c | 9 ++------- src/libratbag-hidraw.c | 1 - src/libratbag.c | 3 ++- 6 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index efd6af51..01cf54a5 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -636,13 +636,8 @@ etekcity_probe(struct ratbag_device *device) int active_idx; rc = ratbag_open_hidraw(device); - if (rc) { - log_error(device->ratbag, - "Can't open corresponding hidraw node: '%s' (%d)\n", - strerror(-rc), - rc); - return -ENODEV; - } + if (rc) + return rc; if (!ratbag_hidraw_has_report(device, ETEKCITY_REPORT_ID_KEY_MAPPING)) { ratbag_close_hidraw(device); diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 0dfd8afc..71e74590 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -504,16 +504,8 @@ hidpp10drv_probe(struct ratbag_device *device) int nread = 0; rc = ratbag_find_hidraw(device, hidpp10drv_test_hidraw); - if (rc == -ENODEV) { - return rc; - } else if (rc) { - log_error(device->ratbag, - "Can't open corresponding hidraw node: '%s' (%d)\n", - strerror(-rc), - rc); - rc = -ENODEV; + if (rc) goto err; - } drv_data = zalloc(sizeof(*drv_data)); hidpp_device_init(&base, device->hidraw.fd); diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index ba333cb2..66fdce04 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -782,15 +782,8 @@ hidpp20drv_probe(struct ratbag_device *device) struct hidpp20_device *dev; rc = ratbag_find_hidraw(device, hidpp20drv_test_hidraw); - if (rc == -ENODEV) { + if (rc) return rc; - } else if (rc) { - log_error(device->ratbag, - "Can't open corresponding hidraw node: '%s' (%d)\n", - strerror(-rc), - rc); - return -ENODEV; - } drv_data = zalloc(sizeof(*drv_data)); ratbag_set_drv_data(device, drv_data); diff --git a/src/driver-roccat.c b/src/driver-roccat.c index ec702a0e..922ece9c 100644 --- a/src/driver-roccat.c +++ b/src/driver-roccat.c @@ -780,13 +780,8 @@ roccat_probe(struct ratbag_device *device) int active_idx; rc = ratbag_open_hidraw(device); - if (rc) { - log_error(device->ratbag, - "Can't open corresponding hidraw node: '%s' (%d)\n", - strerror(-rc), - rc); - return -ENODEV; - } + if (rc) + return rc; if (!ratbag_hidraw_has_report(device, ROCCAT_REPORT_ID_KEY_MAPPING)) { ratbag_close_hidraw(device); diff --git a/src/libratbag-hidraw.c b/src/libratbag-hidraw.c index 977a6825..fa9d178d 100644 --- a/src/libratbag-hidraw.c +++ b/src/libratbag-hidraw.c @@ -1424,7 +1424,6 @@ ratbag_find_hidraw_node(struct ratbag_device *device, skip: ratbag_close_hidraw(device); - rc = -ENODEV; } out: diff --git a/src/libratbag.c b/src/libratbag.c index f552504b..65e18eea 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -330,7 +330,8 @@ ratbag_assign_driver(struct ratbag_device *device, device->driver = NULL; if (rc != -ENODEV) - log_error(ratbag, "%s: no hidraw device found\n", device->name); + log_error(ratbag, "%s: error opening hidraw node (%s)\n", + device->name, strerror(-rc)); return false; }