Skip to content

Commit 223d9a3

Browse files
nehebBartosz Golaszewski
authored andcommitted
gpio: htc-egpio: allocate irq with the main struct
Use a flexible array member to combinwe allocations. Add __counted_by for extra runtime analysis. Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://patch.msgid.link/20260309225204.44789-1-rosenp@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent 0258fe8 commit 223d9a3

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

drivers/gpio/gpio-htc-egpio.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct egpio_info {
4646
uint chained_irq;
4747

4848
/* egpio info */
49-
struct egpio_chip *chip;
5049
int nchips;
50+
struct egpio_chip chip[] __counted_by(nchips);
5151
};
5252

5353
static inline void egpio_writew(u16 value, struct egpio_info *ei, int reg)
@@ -270,10 +270,12 @@ static int __init egpio_probe(struct platform_device *pdev)
270270
int i;
271271

272272
/* Initialize ei data structure. */
273-
ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL);
273+
ei = devm_kzalloc(&pdev->dev, struct_size(ei, chip, pdata->num_chips), GFP_KERNEL);
274274
if (!ei)
275275
return -ENOMEM;
276276

277+
ei->nchips = pdata->num_chips;
278+
277279
spin_lock_init(&ei->lock);
278280

279281
/* Find chained irq */
@@ -302,13 +304,6 @@ static int __init egpio_probe(struct platform_device *pdev)
302304

303305
platform_set_drvdata(pdev, ei);
304306

305-
ei->nchips = pdata->num_chips;
306-
ei->chip = devm_kcalloc(&pdev->dev,
307-
ei->nchips, sizeof(struct egpio_chip),
308-
GFP_KERNEL);
309-
if (!ei->chip)
310-
return -ENOMEM;
311-
312307
for (i = 0; i < ei->nchips; i++) {
313308
ei->chip[i].reg_start = pdata->chip[i].reg_start;
314309
ei->chip[i].cached_values = pdata->chip[i].initial_values;

0 commit comments

Comments
 (0)