From 6c3a8aa90eb24f6bc5f768c4fdc3bef6d601936d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 3 Sep 2015 12:41:49 +1000 Subject: [PATCH] Abort if zalloc fails Let's not pretend we will handle out-of-memory errors correctly, and really, it's not something we really need to be worried about. Signed-off-by: Peter Hutterer --- src/driver-etekcity.c | 3 --- src/driver-hidpp10.c | 4 ---- src/driver-hidpp20.c | 3 --- src/hidpp20.c | 8 -------- src/libratbag-util.h | 6 +++++- src/libratbag.c | 17 ----------------- 6 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index d968028e..fe6ebda9 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -687,9 +687,6 @@ etekcity_probe(struct ratbag_device *device, const struct ratbag_id id) } drv_data = zalloc(sizeof(*drv_data)); - if (!drv_data) - return -ENODEV; - ratbag_set_drv_data(device, drv_data); /* retrieve the "on-to-go" speed setting */ diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 21ff0cbd..d262b4f0 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -208,10 +208,6 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id) } drv_data = zalloc(sizeof(*drv_data)); - if (!drv_data) { - rc = -ENODEV; - goto err; - } /* We can treat all devices as wired devices here. If we talk to the * correct hidraw device the kernel adjusts the device index for us, diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 18156923..a2d7f30f 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -443,9 +443,6 @@ hidpp20drv_probe(struct ratbag_device *device, const struct ratbag_id id) } drv_data = zalloc(sizeof(*drv_data)); - if (!drv_data) - return -ENODEV; - ratbag_set_drv_data(device, drv_data); drv_data->proto_major = 1; diff --git a/src/hidpp20.c b/src/hidpp20.c index 4779e5a8..eb6438c6 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -325,8 +325,6 @@ int hidpp20_feature_set_get(struct ratbag_device *device, } flist = zalloc(feature_count * sizeof(struct hidpp20_feature)); - if (!flist) - return -ENOMEM; for (i = 0; i < feature_count; i++) { rc = hidpp20_feature_set_get_feature_id(device, @@ -464,8 +462,6 @@ hidpp20_kbd_reprogrammable_keys_get_controls(struct ratbag_device *device, } c_list = zalloc(num_controls * sizeof(struct hidpp20_control_id)); - if (!c_list) - return -ENOMEM; for (i = 0; i < num_controls; i++) { control = &c_list[i]; @@ -608,8 +604,6 @@ int hidpp20_special_key_mouse_get_controls(struct ratbag_device *device, } c_list = zalloc(num_controls * sizeof(struct hidpp20_control_id)); - if (!c_list) - return -ENOMEM; for (i = 0; i < num_controls; i++) { control = &c_list[i]; @@ -851,8 +845,6 @@ int hidpp20_adjustable_dpi_get_sensors(struct ratbag_device *device, } s_list = zalloc(num_sensors * sizeof(struct hidpp20_sensor)); - if (!s_list) - return -ENOMEM; for (i = 0; i < num_sensors; i++) { sensor = &s_list[i]; diff --git a/src/libratbag-util.h b/src/libratbag-util.h index ad9640b0..3bd12a2a 100644 --- a/src/libratbag-util.h +++ b/src/libratbag-util.h @@ -92,7 +92,11 @@ strncpy_safe(char *dest, const char *src, size_t n) static inline void * zalloc(size_t size) { - return calloc(1, size); + void *p = calloc(1, size); + + if (!p) + abort(); + return p; } static inline void diff --git a/src/libratbag.c b/src/libratbag.c index c9b248bf..ffd4bd3b 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -99,11 +99,6 @@ log_buffer(struct ratbag *ratbag, buf_len += 1; /* terminating '\0' */ output_buf = zalloc(buf_len); - if (!output_buf) { - log_msg(ratbag, priority, "%s ......", header ? header : ""); - return; - } - n = 0; if (header) n += sprintf(output_buf, "%s", header); @@ -255,9 +250,6 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device, struct ratbag_device *device = NULL; device = zalloc(sizeof(*device)); - if (!device) - return NULL; - device->name = strdup(name); if (!name) { @@ -498,9 +490,6 @@ ratbag_create_context(const struct ratbag_interface *interface, return NULL; ratbag = zalloc(sizeof(*ratbag)); - if (!ratbag) - return NULL; - ratbag->refcount = 1; ratbag->interface = interface; ratbag->userdata = userdata; @@ -553,9 +542,6 @@ ratbag_create_button(struct ratbag_profile *profile, unsigned int index) struct ratbag_button *button; button = zalloc(sizeof(*button)); - if (!button) - return NULL; - button->refcount = 1; button->profile = profile; button->index = index; @@ -590,9 +576,6 @@ ratbag_create_profile(struct ratbag_device *device, unsigned i; profile = zalloc(sizeof(*profile)); - if (!profile) - return NULL; - profile->refcount = 1; profile->device = device; profile->index = index;