Skip to content

Commit 7693de9

Browse files
geertudlezcano
authored andcommitted
clocksource/drivers/sh_mtu2: Do not loop using platform_get_irq_by_name()
As platform_get_irq_by_name() now prints an error when the interrupt does not exist, looping over possibly non-existing interrupts causes the printing of scary messages like: sh_mtu2 fcff0000.timer: IRQ tgi1a not found sh_mtu2 fcff0000.timer: IRQ tgi2a not found Fix this by using the platform_irq_count() helper, to avoid touching non-existent interrupts. Limit the returned number of interrupts to the maximum number of channels currently supported by the driver in a future-proof way, i.e. using ARRAY_SIZE() instead of a hardcoded number. Fixes: 7723f4c ("driver core: platform: Add an error message to platform_get_irq*()") Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 41d49e7 commit 7693de9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/clocksource/sh_mtu2.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ static int sh_mtu2_register(struct sh_mtu2_channel *ch, const char *name)
328328
return 0;
329329
}
330330

331+
static const unsigned int sh_mtu2_channel_offsets[] = {
332+
0x300, 0x380, 0x000,
333+
};
334+
331335
static int sh_mtu2_setup_channel(struct sh_mtu2_channel *ch, unsigned int index,
332336
struct sh_mtu2_device *mtu)
333337
{
334-
static const unsigned int channel_offsets[] = {
335-
0x300, 0x380, 0x000,
336-
};
337338
char name[6];
338339
int irq;
339340
int ret;
@@ -356,7 +357,7 @@ static int sh_mtu2_setup_channel(struct sh_mtu2_channel *ch, unsigned int index,
356357
return ret;
357358
}
358359

359-
ch->base = mtu->mapbase + channel_offsets[index];
360+
ch->base = mtu->mapbase + sh_mtu2_channel_offsets[index];
360361
ch->index = index;
361362

362363
return sh_mtu2_register(ch, dev_name(&mtu->pdev->dev));
@@ -408,7 +409,12 @@ static int sh_mtu2_setup(struct sh_mtu2_device *mtu,
408409
}
409410

410411
/* Allocate and setup the channels. */
411-
mtu->num_channels = 3;
412+
ret = platform_irq_count(pdev);
413+
if (ret < 0)
414+
goto err_unmap;
415+
416+
mtu->num_channels = min_t(unsigned int, ret,
417+
ARRAY_SIZE(sh_mtu2_channel_offsets));
412418

413419
mtu->channels = kcalloc(mtu->num_channels, sizeof(*mtu->channels),
414420
GFP_KERNEL);

0 commit comments

Comments
 (0)