diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/leds | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/leds')
| -rw-r--r-- | drivers/leds/led-triggers.c | 2 | ||||
| -rw-r--r-- | drivers/leds/rgb/leds-qcom-lpg.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-activity.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-backlight.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-gpio.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-heartbeat.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-input-events.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-netdev.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-oneshot.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-pattern.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-transient.c | 2 | ||||
| -rw-r--r-- | drivers/leds/trigger/ledtrig-tty.c | 2 | ||||
| -rw-r--r-- | drivers/leds/uleds.c | 2 |
13 files changed, 13 insertions, 13 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 3799dcc1cf07..2fdb713307c3 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -486,7 +486,7 @@ void led_trigger_register_simple(const char *name, struct led_trigger **tp) struct led_trigger *trig; int err; - trig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); + trig = kzalloc_obj(struct led_trigger, GFP_KERNEL); if (trig) { trig->name = name; diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index f54851dfb42f..138c8fb3514c 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -996,7 +996,7 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, if (len % 2) return -EINVAL; - pattern = kcalloc(len / 2, sizeof(*pattern), GFP_KERNEL); + pattern = kzalloc_objs(*pattern, len / 2, GFP_KERNEL); if (!pattern) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-activity.c b/drivers/leds/trigger/ledtrig-activity.c index c973246a57f9..4f0c16b04876 100644 --- a/drivers/leds/trigger/ledtrig-activity.c +++ b/drivers/leds/trigger/ledtrig-activity.c @@ -188,7 +188,7 @@ static int activity_activate(struct led_classdev *led_cdev) { struct activity_data *activity_data; - activity_data = kzalloc(sizeof(*activity_data), GFP_KERNEL); + activity_data = kzalloc_obj(*activity_data, GFP_KERNEL); if (!activity_data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c index c1f0f5becaee..80b33f13beee 100644 --- a/drivers/leds/trigger/ledtrig-backlight.c +++ b/drivers/leds/trigger/ledtrig-backlight.c @@ -102,7 +102,7 @@ static int bl_trig_activate(struct led_classdev *led) { struct bl_trig_notifier *n; - n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL); + n = kzalloc_obj(struct bl_trig_notifier, GFP_KERNEL); if (!n) return -ENOMEM; led_set_trigger_data(led, n); diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index 7f6a2352b0ac..eec6de5ea3bc 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c @@ -78,7 +78,7 @@ static int gpio_trig_activate(struct led_classdev *led) struct device *dev = led->dev; int ret; - gpio_data = kzalloc(sizeof(*gpio_data), GFP_KERNEL); + gpio_data = kzalloc_obj(*gpio_data, GFP_KERNEL); if (!gpio_data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c index 40eb61b6d54e..6ad8b486b058 100644 --- a/drivers/leds/trigger/ledtrig-heartbeat.c +++ b/drivers/leds/trigger/ledtrig-heartbeat.c @@ -129,7 +129,7 @@ static int heartbeat_trig_activate(struct led_classdev *led_cdev) { struct heartbeat_trig_data *heartbeat_data; - heartbeat_data = kzalloc(sizeof(*heartbeat_data), GFP_KERNEL); + heartbeat_data = kzalloc_obj(*heartbeat_data, GFP_KERNEL); if (!heartbeat_data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-input-events.c b/drivers/leds/trigger/ledtrig-input-events.c index 3c6414259c27..dcdea964311d 100644 --- a/drivers/leds/trigger/ledtrig-input-events.c +++ b/drivers/leds/trigger/ledtrig-input-events.c @@ -75,7 +75,7 @@ static int input_events_connect(struct input_handler *handler, struct input_dev struct input_handle *handle; int ret; - handle = kzalloc(sizeof(*handle), GFP_KERNEL); + handle = kzalloc_obj(*handle, GFP_KERNEL); if (!handle) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index c15efe3e5078..e15e7dcdbcd9 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -691,7 +691,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) struct device *dev; int rc; - trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); + trigger_data = kzalloc_obj(struct led_netdev_data, GFP_KERNEL); if (!trigger_data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c index bee3bd452abf..b825e607bb9f 100644 --- a/drivers/leds/trigger/ledtrig-oneshot.c +++ b/drivers/leds/trigger/ledtrig-oneshot.c @@ -159,7 +159,7 @@ static int oneshot_trig_activate(struct led_classdev *led_cdev) { struct oneshot_trig_data *oneshot_data; - oneshot_data = kzalloc(sizeof(*oneshot_data), GFP_KERNEL); + oneshot_data = kzalloc_obj(*oneshot_data, GFP_KERNEL); if (!oneshot_data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c index 9af3c18f14f4..9eaae7757c8e 100644 --- a/drivers/leds/trigger/ledtrig-pattern.c +++ b/drivers/leds/trigger/ledtrig-pattern.c @@ -465,7 +465,7 @@ static int pattern_trig_activate(struct led_classdev *led_cdev) { struct pattern_trig_data *data; - data = kzalloc(sizeof(*data), GFP_KERNEL); + data = kzalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-transient.c b/drivers/leds/trigger/ledtrig-transient.c index 20f1351464b1..258e5d8db5b2 100644 --- a/drivers/leds/trigger/ledtrig-transient.c +++ b/drivers/leds/trigger/ledtrig-transient.c @@ -164,7 +164,7 @@ static int transient_trig_activate(struct led_classdev *led_cdev) { struct transient_trig_data *tdata; - tdata = kzalloc(sizeof(struct transient_trig_data), GFP_KERNEL); + tdata = kzalloc_obj(struct transient_trig_data, GFP_KERNEL); if (!tdata) return -ENOMEM; diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c index 8cf1485e8165..4ce915e417f8 100644 --- a/drivers/leds/trigger/ledtrig-tty.c +++ b/drivers/leds/trigger/ledtrig-tty.c @@ -312,7 +312,7 @@ static int ledtrig_tty_activate(struct led_classdev *led_cdev) { struct ledtrig_tty_data *trigger_data; - trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); + trigger_data = kzalloc_obj(*trigger_data, GFP_KERNEL); if (!trigger_data) return -ENOMEM; diff --git a/drivers/leds/uleds.c b/drivers/leds/uleds.c index 374a841f18c3..b70d203d0b16 100644 --- a/drivers/leds/uleds.c +++ b/drivers/leds/uleds.c @@ -53,7 +53,7 @@ static int uleds_open(struct inode *inode, struct file *file) { struct uleds_device *udev; - udev = kzalloc(sizeof(*udev), GFP_KERNEL); + udev = kzalloc_obj(*udev, GFP_KERNEL); if (!udev) return -ENOMEM; |
