forked from drath/libratbag
ratbagd: use zalloc instead of calloc
Because we really don't care about OOM beside blowing up. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
9450d1402f
commit
a938521c9e
@@ -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 = [
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <linux/input.h>
|
||||
#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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <systemd/sd-bus.h>
|
||||
#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;
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <systemd/sd-event.h>
|
||||
#include "ratbagd.h"
|
||||
#include "shared-macro.h"
|
||||
#include "libratbag-util.h"
|
||||
|
||||
struct ratbagd_resolution {
|
||||
struct ratbag_resolution *lib_resolution;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <systemd/sd-event.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user