From 52fea6f3ceb25fd52d539e46afcb584b888d96a5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:11:26 +1000 Subject: [PATCH 1/7] Remove superfluous check for strdup() ENOMEM If that happens, strdup_safe() will abort. Signed-off-by: Peter Hutterer --- src/libratbag.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 896e425b..599b322e 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -156,12 +156,6 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device, device = zalloc(sizeof(*device)); device->name = strdup_safe(name); - - if (!name) { - free(device); - return NULL; - } - device->ratbag = ratbag_ref(ratbag); device->refcount = 1; if (udev_device) From 014c4105f430a30eec059b97bee4294fe64e7c79 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:12:22 +1000 Subject: [PATCH 2/7] Remove superfluous check for a NULL udev device If the udev device is NULL, we should fail a lot earlier Signed-off-by: Peter Hutterer --- src/libratbag.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 599b322e..0ff064eb 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -158,9 +158,7 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device, device->name = strdup_safe(name); device->ratbag = ratbag_ref(ratbag); device->refcount = 1; - if (udev_device) - device->udev_device = udev_device_ref(udev_device); - + device->udev_device = udev_device_ref(udev_device); device->ids = *id; list_init(&device->profiles); From f5ff267c541cf2f2fae879a0c1c955360a645420 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:17:10 +1000 Subject: [PATCH 3/7] Improve a few error messages Signed-off-by: Peter Hutterer --- src/libratbag.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 0ff064eb..fd8daa91 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -216,7 +216,7 @@ ratbag_sanity_check_device(struct ratbag_device *device) * accidental negative */ if (device->num_profiles == 0 || device->num_profiles > 16) { log_bug_libratbag(ratbag, - "%s: invalid number of profiles %d\n", + "%s: invalid number of profiles (%d)\n", device->name, device->num_profiles); goto out; @@ -242,8 +242,9 @@ ratbag_sanity_check_device(struct ratbag_device *device) nres = ratbag_profile_get_num_resolutions(profile); if (nres == 0 || nres > 16) { log_bug_libratbag(ratbag, - "%s: minimum 1 resolution required\n", - device->name); + "%s: invalid number of resolutions (%d)\n", + device->name, + nres); goto out; } @@ -254,7 +255,7 @@ ratbag_sanity_check_device(struct ratbag_device *device) /* Require 1 active profile */ if (!has_active) { log_bug_libratbag(ratbag, - "%s: no active profile found\n", + "%s: no profile set as active profile\n", device->name); goto out; } @@ -291,7 +292,7 @@ ratbag_find_driver(struct ratbag_device *device, } if (!device->driver) { - log_error(ratbag, "%s: driver specified in hwdb not found: %s\n", + log_error(ratbag, "%s: driver '%s' does not exist\n", device->name, driver_name); return NULL; } From 855a6bd831bc9892402663d3484da97780f28b37 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:21:33 +1000 Subject: [PATCH 4/7] Fix error message on ENODEV Signed-off-by: Peter Hutterer --- src/libratbag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libratbag.c b/src/libratbag.c index fd8daa91..ff7c8cee 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -312,7 +312,7 @@ ratbag_find_driver(struct ratbag_device *device, device->driver = NULL; - if (rc != -ENODEV) { + if (rc == -ENODEV) { log_error(ratbag, "%s: no hidraw device found\n", device->name); return NULL; } From bfe6d446adae929ca9d399d7934957dd571c4258 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:27:03 +1000 Subject: [PATCH 5/7] Comment typo fixes Signed-off-by: Peter Hutterer --- src/libratbag.c | 2 +- src/libratbag.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index ff7c8cee..62e982b4 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -329,7 +329,7 @@ get_device_name(struct udev_device *device) if (!prop) return NULL; - /* udev name is inclosed by " */ + /* udev name is enclosed by " */ return strndup(&prop[1], strlen(prop) - 2); } diff --git a/src/libratbag.h b/src/libratbag.h index 5e141c99..f2fd193f 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -1345,7 +1345,7 @@ ratbag_button_get_macro_event_key(struct ratbag_button *button, unsigned int ind * @param button A previously initialized ratbag button * @param index An index of the event within the macro we are interested in. * - * @return The tiemout of the event at the given index + * @return The timeout of the event at the given index */ int ratbag_button_get_macro_event_timeout(struct ratbag_button *button, unsigned int index); From 6f9aa5aa24d67db3eb42be95082e0c9203d47c33 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:42:44 +1000 Subject: [PATCH 6/7] Coding style fixes Signed-off-by: Peter Hutterer --- src/libratbag.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 62e982b4..07f31caf 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -460,7 +460,7 @@ ratbag_register_driver(struct ratbag *ratbag, struct ratbag_driver *driver) LIBRATBAG_EXPORT struct ratbag * ratbag_create_context(const struct ratbag_interface *interface, - void *userdata) + void *userdata) { struct ratbag *ratbag; @@ -721,9 +721,9 @@ ratbag_profile_set_active(struct ratbag_profile *profile) if (rc) return rc; - list_for_each(p, &device->profiles, link) { + list_for_each(p, &device->profiles, link) p->is_active = false; - } + profile->is_active = true; return rc; } From be008cd86c59043a2c9b572d7dc9195995415ce2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Mar 2016 12:43:47 +1000 Subject: [PATCH 7/7] Switch ratbag_get_num_resolutions() to return an unsigned Signed-off-by: Peter Hutterer --- src/libratbag.c | 6 +++--- src/libratbag.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 07f31caf..c8929f70 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -728,7 +728,7 @@ ratbag_profile_set_active(struct ratbag_profile *profile) return rc; } -LIBRATBAG_EXPORT int +LIBRATBAG_EXPORT unsigned int ratbag_profile_get_num_resolutions(struct ratbag_profile *profile) { return profile->resolution.num_modes; @@ -738,9 +738,9 @@ LIBRATBAG_EXPORT struct ratbag_resolution * ratbag_profile_get_resolution(struct ratbag_profile *profile, unsigned int idx) { struct ratbag_resolution *res; - int max = ratbag_profile_get_num_resolutions(profile); + unsigned max = ratbag_profile_get_num_resolutions(profile); - if (max < 0 || idx >= (unsigned int)max) + if (idx >= max) return NULL; res = &profile->resolution.modes[idx]; diff --git a/src/libratbag.h b/src/libratbag.h index f2fd193f..2606288e 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -620,7 +620,7 @@ ratbag_profile_set_active(struct ratbag_profile *profile); * * @return The number of profiles available. */ -int +unsigned int ratbag_profile_get_num_resolutions(struct ratbag_profile *profile); /**