Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mailbox: hi6220: kzalloc + kcalloc to kzalloc

Reduce allocations to a single one by using a flexible array member.

Allows using __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>

authored by

Rosen Penev and committed by
Jassi Brar
df1de2ab f9f0df23

+5 -9
+5 -9
drivers/mailbox/hi6220-mailbox.c
··· 79 79 /* region for mailbox */ 80 80 void __iomem *base; 81 81 82 - unsigned int chan_num; 83 - struct hi6220_mbox_chan *mchan; 84 - 85 82 void *irq_map_chan[MBOX_CHAN_MAX]; 86 83 struct mbox_chan *chan; 87 84 struct mbox_controller controller; 85 + 86 + unsigned int chan_num; 87 + struct hi6220_mbox_chan mchan[] __counted_by(chan_num); 88 88 }; 89 89 90 90 static void mbox_set_state(struct hi6220_mbox *mbox, ··· 267 267 struct hi6220_mbox *mbox; 268 268 int i, err; 269 269 270 - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL); 270 + mbox = devm_kzalloc(dev, struct_size(mbox, mchan, MBOX_CHAN_MAX), GFP_KERNEL); 271 271 if (!mbox) 272 272 return -ENOMEM; 273 273 274 - mbox->dev = dev; 275 274 mbox->chan_num = MBOX_CHAN_MAX; 276 - mbox->mchan = devm_kcalloc(dev, 277 - mbox->chan_num, sizeof(*mbox->mchan), GFP_KERNEL); 278 - if (!mbox->mchan) 279 - return -ENOMEM; 275 + mbox->dev = dev; 280 276 281 277 mbox->chan = devm_kcalloc(dev, 282 278 mbox->chan_num, sizeof(*mbox->chan), GFP_KERNEL);