ALSA: trivial conversions to struct_size()
cover 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(-)
Signature · 1 line
2.16.4
PATCH 1/3 ALSA: control: Use struct_size()
For code simplification and safety, use struct_size() macro for calculating the snd_kcontrol object size with the variable array.
--- sound/core/control.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/core/control.c +1 -5
@@ -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 ;
Signature · 1 line
2.16.4
PATCH 2/3 ALSA: hda: Use struct_size()
In reply to Takashi IwaiFor code simplification and safety, use struct_size() macro for calculating the hda_conn_list object size with the variable array.
--- sound/pci/hda/hda_codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +1 -1
@@ -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;
Signature · 1 line
2.16.4
PATCH 3/3 ALSA: hda/ca0132: Use struct_size()
In reply to Takashi IwaiFor code simplification and safety, use struct_size() macro for calculating the dsp_image_seg object size.
--- sound/pci/hda/patch_ca0132.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/hda/patch_ca0132.c +1 -1
@@ -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(
Signature · 1 line
2.16.4