summaryrefslogtreecommitdiff
path: root/sound/core/oss
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /sound/core/oss
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'sound/core/oss')
-rw-r--r--sound/core/oss/mixer_oss.c32
-rw-r--r--sound/core/oss/pcm_oss.c18
-rw-r--r--sound/core/oss/pcm_plugin.c3
3 files changed, 27 insertions, 26 deletions
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index f4ad0bfb4dac..05c8e44cd428 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -47,7 +47,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
snd_card_unref(card);
return err;
}
- fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL);
+ fmixer = kzalloc_obj(*fmixer, GFP_KERNEL);
if (fmixer == NULL) {
snd_card_file_remove(card, file);
snd_card_unref(card);
@@ -530,9 +530,9 @@ static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
return;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return;
if (kctl->info(kctl, uinfo))
@@ -566,9 +566,9 @@ static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
return;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return;
if (kctl->info(kctl, uinfo))
@@ -629,9 +629,9 @@ static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer,
return;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return;
if (kctl->info(kctl, uinfo))
@@ -669,9 +669,9 @@ static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
return;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return;
if (kctl->info(kctl, uinfo))
@@ -798,9 +798,9 @@ static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
int err, idx;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return -ENOMEM;
guard(rwsem_read)(&card->controls_rwsem);
@@ -843,9 +843,9 @@ static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
unsigned int idx;
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
struct snd_ctl_elem_value *uctl __free(kfree) =
- kzalloc(sizeof(*uctl), GFP_KERNEL);
+ kzalloc_obj(*uctl, GFP_KERNEL);
if (uinfo == NULL || uctl == NULL)
return -ENOMEM;
guard(rwsem_read)(&card->controls_rwsem);
@@ -1027,7 +1027,7 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer,
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
if (kctl) {
struct snd_ctl_elem_info *uinfo __free(kfree) =
- kzalloc(sizeof(*uinfo), GFP_KERNEL);
+ kzalloc_obj(*uinfo, GFP_KERNEL);
if (!uinfo)
return -ENOMEM;
@@ -1055,7 +1055,7 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer,
}
}
if (slot.present != 0) {
- pslot = kmalloc(sizeof(slot), GFP_KERNEL);
+ pslot = kmalloc_obj(slot, GFP_KERNEL);
if (! pslot)
return -ENOMEM;
*pslot = slot;
@@ -1315,7 +1315,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
int idx, err;
- mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
+ mixer = kzalloc_objs(*mixer, 2, GFP_KERNEL);
if (mixer == NULL)
return -ENOMEM;
mutex_init(&mixer->reg_mutex);
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 3bc94d34b35e..cf3509c2be15 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -398,7 +398,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
}
struct snd_pcm_hw_params *save __free(kfree) =
- kmalloc(sizeof(*save), GFP_KERNEL);
+ kmalloc_obj(*save, GFP_KERNEL);
if (save == NULL)
return -ENOMEM;
*save = *params;
@@ -411,7 +411,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
goto _end;
struct snd_pcm_hw_params *params1 __free(kfree) =
- kmalloc(sizeof(*params1), GFP_KERNEL);
+ kmalloc_obj(*params1, GFP_KERNEL);
if (params1 == NULL)
return -ENOMEM;
*params1 = *save;
@@ -786,7 +786,7 @@ static int choose_rate(struct snd_pcm_substream *substream,
unsigned int rate, prev;
struct snd_pcm_hw_params *save __free(kfree) =
- kmalloc(sizeof(*save), GFP_KERNEL);
+ kmalloc_obj(*save, GFP_KERNEL);
if (save == NULL)
return -ENOMEM;
*save = *params;
@@ -861,9 +861,9 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
if (!runtime->oss.params)
return 0;
- sw_params = kzalloc(sizeof(*sw_params), GFP_KERNEL);
- params = kmalloc(sizeof(*params), GFP_KERNEL);
- sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
+ sw_params = kzalloc_obj(*sw_params, GFP_KERNEL);
+ params = kmalloc_obj(*params, GFP_KERNEL);
+ sparams = kmalloc_obj(*sparams, GFP_KERNEL);
if (!sw_params || !params || !sparams) {
err = -ENOMEM;
goto failure;
@@ -1859,7 +1859,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
AFMT_S24_PACKED;
struct snd_pcm_hw_params *params __free(kfree) =
- kmalloc(sizeof(*params), GFP_KERNEL);
+ kmalloc_obj(*params, GFP_KERNEL);
if (!params)
return -ENOMEM;
_snd_pcm_hw_params_any(params);
@@ -2418,7 +2418,7 @@ static int snd_pcm_oss_open_file(struct file *file,
if (rpcm_oss_file)
*rpcm_oss_file = NULL;
- pcm_oss_file = kzalloc(sizeof(*pcm_oss_file), GFP_KERNEL);
+ pcm_oss_file = kzalloc_obj(*pcm_oss_file, GFP_KERNEL);
if (pcm_oss_file == NULL)
return -ENOMEM;
@@ -3032,7 +3032,7 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
}
} while (*str);
if (setup == NULL) {
- setup = kmalloc(sizeof(*setup), GFP_KERNEL);
+ setup = kmalloc_obj(*setup, GFP_KERNEL);
if (! setup) {
buffer->error = -ENOMEM;
return;
diff --git a/sound/core/oss/pcm_plugin.c b/sound/core/oss/pcm_plugin.c
index a4c8c9f538f1..e5a0e3c79f7e 100644
--- a/sound/core/oss/pcm_plugin.c
+++ b/sound/core/oss/pcm_plugin.c
@@ -163,7 +163,8 @@ int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
channels = src_format->channels;
else
channels = dst_format->channels;
- plugin->buf_channels = kcalloc(channels, sizeof(*plugin->buf_channels), GFP_KERNEL);
+ plugin->buf_channels = kzalloc_objs(*plugin->buf_channels, channels,
+ GFP_KERNEL);
if (plugin->buf_channels == NULL) {
snd_pcm_plugin_free(plugin);
return -ENOMEM;