diff --git a/meson.build b/meson.build index 4575cedd..668e97e6 100644 --- a/meson.build +++ b/meson.build @@ -438,7 +438,8 @@ src_ratbagd = [ 'ratbagd/ratbagd-device.c', 'ratbagd/ratbagd-profile.c', 'ratbagd/ratbagd-resolution.c', - 'src/libratbag-util.h' + 'src/libratbag-util.h', + 'src/libratbag-util.c', ] deps_ratbagd = [ diff --git a/ratbagd/ratbagd-button.c b/ratbagd/ratbagd-button.c index d6595520..86a0cc94 100644 --- a/ratbagd/ratbagd-button.c +++ b/ratbagd/ratbagd-button.c @@ -36,6 +36,7 @@ #include #include "ratbagd.h" #include "shared-macro.h" +#include "libratbag-util.h" struct ratbagd_button { struct ratbag_button *lib_button; @@ -526,10 +527,7 @@ int ratbagd_button_new(struct ratbagd_button **out, assert(out); assert(lib_button); - button = calloc(1, sizeof(*button)); - if (!button) - return -ENOMEM; - + button = zalloc(sizeof(*button)); button->lib_button = lib_button; button->index = index; diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index 11650b6e..c9a485bc 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -97,9 +97,7 @@ static int ratbagd_device_list_profiles(sd_bus *bus, char **profiles; unsigned int i; - profiles = calloc(device->n_profiles + 1, sizeof(char *)); - if (!profiles) - return -ENOMEM; + profiles = zalloc((device->n_profiles + 1) * sizeof(char *)); for (i = 0; i < device->n_profiles; ++i) { profile = device->profiles[i]; @@ -373,10 +371,7 @@ int ratbagd_device_new(struct ratbagd_device **out, assert(ctx); assert(name); - device = calloc(1, sizeof(*device)); - if (!device) - return -ENOMEM; - + device = zalloc(sizeof(*device)); device->ctx = ctx; rbnode_init(&device->node); device->lib_device = ratbag_device_ref(lib_device); @@ -391,9 +386,7 @@ int ratbagd_device_new(struct ratbagd_device **out, device->n_profiles = ratbag_device_get_num_profiles(device->lib_device); - device->profiles = calloc(device->n_profiles, sizeof(*device->profiles)); - if (!device->profiles) - return -ENOMEM; + device->profiles = zalloc(device->n_profiles * sizeof(*device->profiles)); log_verbose("%s: \"%s\", %d profiles\n", name, diff --git a/ratbagd/ratbagd-led.c b/ratbagd/ratbagd-led.c index 8befd74b..796e3338 100644 --- a/ratbagd/ratbagd-led.c +++ b/ratbagd/ratbagd-led.c @@ -31,6 +31,7 @@ #include #include "ratbagd.h" #include "shared-macro.h" +#include "libratbag-util.h" struct ratbagd_led { struct ratbag_led *lib_led; @@ -273,10 +274,7 @@ int ratbagd_led_new(struct ratbagd_led **out, assert(out); assert(lib_led); - led = calloc(1, sizeof(*led)); - if (!led) - return -ENOMEM; - + led = zalloc(sizeof(*led)); led->lib_led = lib_led; led->index = index; diff --git a/ratbagd/ratbagd-profile.c b/ratbagd/ratbagd-profile.c index 23acac0f..b3d0872b 100644 --- a/ratbagd/ratbagd-profile.c +++ b/ratbagd/ratbagd-profile.c @@ -36,6 +36,7 @@ #include "ratbagd.h" #include "libratbag-util.h" #include "shared-macro.h" +#include "libratbag-util.h" struct ratbagd_profile { struct ratbagd_device *device; @@ -375,9 +376,7 @@ int ratbagd_profile_new(struct ratbagd_profile **out, assert(out); assert(lib_profile); - profile = calloc(1, sizeof(*profile)); - if (!profile) - return -ENOMEM; + profile = zalloc(sizeof(*profile)); profile->device = device; profile->lib_profile = lib_profile; @@ -392,19 +391,13 @@ int ratbagd_profile_new(struct ratbagd_profile **out, return r; profile->n_resolutions = ratbag_profile_get_num_resolutions(profile->lib_profile); - profile->resolutions = calloc(profile->n_resolutions, sizeof(*profile->resolutions)); - if (!profile->resolutions) - return -ENOMEM; + profile->resolutions = zalloc(profile->n_resolutions * sizeof(*profile->resolutions)); profile->n_buttons = ratbagd_device_get_num_buttons(device); - profile->buttons = calloc(profile->n_buttons, sizeof(*profile->buttons)); - if (!profile->buttons) - return -ENOMEM; + profile->buttons = zalloc(profile->n_buttons * sizeof(*profile->buttons)); profile->n_leds = ratbagd_device_get_num_leds(device); - profile->leds = calloc(profile->n_leds, sizeof(*profile->leds)); - if (!profile->leds) - return -ENOMEM; + profile->leds = zalloc(profile->n_leds * sizeof(*profile->leds)); for (i = 0; i < profile->n_resolutions; ++i) { resolution = ratbag_profile_get_resolution(profile->lib_profile, i); @@ -522,9 +515,7 @@ static int ratbagd_profile_list_resolutions(sd_bus *bus, char **resolutions; unsigned int i; - resolutions = calloc(profile->n_resolutions + 1, sizeof(char *)); - if (!resolutions) - return -ENOMEM; + resolutions = zalloc((profile->n_resolutions + 1) * sizeof(char *)); for (i = 0; i < profile->n_resolutions; ++i) { resolution = profile->resolutions[i]; @@ -591,9 +582,7 @@ static int ratbagd_profile_list_buttons(sd_bus *bus, char **buttons; unsigned int i; - buttons = calloc(profile->n_buttons + 1, sizeof(char *)); - if (!buttons) - return -ENOMEM; + buttons = zalloc((profile->n_buttons + 1) * sizeof(char *)); for (i = 0; i < profile->n_buttons; ++i) { button = profile->buttons[i]; @@ -659,9 +648,7 @@ static int ratbagd_profile_list_leds(sd_bus *bus, char **leds; unsigned int i; - leds = calloc(profile->n_leds + 1, sizeof(char *)); - if (!leds) - return -ENOMEM; + leds = zalloc((profile->n_leds + 1) * sizeof(char *)); for (i = 0; i < profile->n_leds; ++i) { led = profile->leds[i]; diff --git a/ratbagd/ratbagd-resolution.c b/ratbagd/ratbagd-resolution.c index ade03f14..0054ccbc 100644 --- a/ratbagd/ratbagd-resolution.c +++ b/ratbagd/ratbagd-resolution.c @@ -35,6 +35,7 @@ #include #include "ratbagd.h" #include "shared-macro.h" +#include "libratbag-util.h" struct ratbagd_resolution { struct ratbag_resolution *lib_resolution; diff --git a/ratbagd/ratbagd.c b/ratbagd/ratbagd.c index bcf741fc..bca3580f 100644 --- a/ratbagd/ratbagd.c +++ b/ratbagd/ratbagd.c @@ -35,6 +35,7 @@ #include #include "ratbagd.h" #include "shared-macro.h" +#include "libratbag-util.h" static bool verbose = false; @@ -524,10 +525,7 @@ static int ratbagd_new(struct ratbagd **out) _cleanup_(ratbagd_freep) struct ratbagd *ctx = NULL; int r; - ctx = calloc(1, sizeof(*ctx)); - if (!ctx) - return -ENOMEM; - + ctx = zalloc(sizeof(*ctx)); ctx->themes = SVG_THEMES; r = sd_event_default(&ctx->event);