[alsa-devel] [PATCH 0/3] ALSA: trivial conversions to struct_size()
Hi,
there are a few more places that can be better written with struct_size() macro. Let's replace them.
Takashi
===
Takashi Iwai (3): ALSA: control: Use struct_size() ALSA: hda: Use struct_size() ALSA: hda/ca0132: Use struct_size()
sound/core/control.c | 6 +----- sound/pci/hda/hda_codec.c | 2 +- sound/pci/hda/patch_ca0132.c | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-)
For code simplification and safety, use struct_size() macro for calculating the snd_kcontrol object size with the variable array.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/core/control.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/sound/core/control.c b/sound/core/control.c index a5cc9a874062..04eb1a15ffb4 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -211,16 +211,12 @@ EXPORT_SYMBOL(snd_ctl_notify); static int snd_ctl_new(struct snd_kcontrol **kctl, unsigned int count, unsigned int access, struct snd_ctl_file *file) { - unsigned int size; unsigned int idx;
if (count == 0 || count > MAX_CONTROL_COUNT) return -EINVAL;
- size = sizeof(struct snd_kcontrol); - size += sizeof(struct snd_kcontrol_volatile) * count; - - *kctl = kzalloc(size, GFP_KERNEL); + *kctl = kzalloc(struct_size(*kctl, vd, count), GFP_KERNEL); if (!*kctl) return -ENOMEM;
For code simplification and safety, use struct_size() macro for calculating the hda_conn_list object size with the variable array.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pci/hda/hda_codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index b20eb7fc83eb..d0f1dbcfbda4 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -122,7 +122,7 @@ static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len, { struct hda_conn_list *p;
- p = kmalloc(sizeof(*p) + len * sizeof(hda_nid_t), GFP_KERNEL); + p = kmalloc(struct_size(p, conns, len), GFP_KERNEL); if (!p) return -ENOMEM; p->len = len;
For code simplification and safety, use struct_size() macro for calculating the dsp_image_seg object size.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pci/hda/patch_ca0132.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index e1ebc6d5f382..de61179c91e2 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -2731,7 +2731,7 @@ static bool is_last(const struct dsp_image_seg *p)
static size_t dsp_sizeof(const struct dsp_image_seg *p) { - return sizeof(*p) + p->count*sizeof(u32); + return struct_size(p, data, p->count); }
static const struct dsp_image_seg *get_next_seg_ptr(
participants (1)
-
Takashi Iwai