2022-12-29 15:11:39

by Cixi Geng

[permalink] [raw]
Subject: [PATCH V4 0/3] Make the irqchip immutable

From: Cixi Geng <[email protected]>

Kernel warns about mutable irq_chips:
"not an immutable chip, please consider fixing!"

Make the struct irq_chip const, flag it as IRQCHIP_IMMUTABLE, add the
new helper functions, and call the appropriate gpiolib functions.

v2 changes:
Split the patch by each driver. and other comment by baolin in[1]

v3 changes:
Fix cocci warnings test by lkp[2].

v4 changes:
Change the irq name.
Keep the same coding style by using offset for irqd_to_hwirq(data)
Add Reviewed-by tag.

[1]:https://lore.kernel.org/all/[email protected]/
[2]:https://lore.kernel.org/all/[email protected]/

Cixi Geng (3):
gpio: eic-sprd: Make the irqchip immutable
gpio: gpio-pmic-eic-sprd: Make the irqchip immutable
gpio: gpio-sprd: Make the irqchip immutable

drivers/gpio/gpio-eic-sprd.c | 23 ++++++++++++++---------
drivers/gpio/gpio-pmic-eic-sprd.c | 29 ++++++++++++++++++-----------
drivers/gpio/gpio-sprd.c | 9 ++++++---
3 files changed, 38 insertions(+), 23 deletions(-)


base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2
--
2.34.1


2022-12-29 15:11:49

by Cixi Geng

[permalink] [raw]
Subject: [PATCH V4 2/3] gpio: gpio-pmic-eic-sprd: Make the irqchip immutable

From: Cixi Geng <[email protected]>

Remove the irq_chip from pmic_eic structure,
use the various calls by defining the statically
irq_chip structure.

Signed-off-by: Cixi Geng <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
---
drivers/gpio/gpio-pmic-eic-sprd.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-pmic-eic-sprd.c b/drivers/gpio/gpio-pmic-eic-sprd.c
index e518490c4b68..c3e4d90f6b18 100644
--- a/drivers/gpio/gpio-pmic-eic-sprd.c
+++ b/drivers/gpio/gpio-pmic-eic-sprd.c
@@ -47,7 +47,6 @@ enum {
/**
* struct sprd_pmic_eic - PMIC EIC controller
* @chip: the gpio_chip structure.
- * @intc: the irq_chip structure.
* @map: the regmap from the parent device.
* @offset: the EIC controller's offset address of the PMIC.
* @reg: the array to cache the EIC registers.
@@ -56,7 +55,6 @@ enum {
*/
struct sprd_pmic_eic {
struct gpio_chip chip;
- struct irq_chip intc;
struct regmap *map;
u32 offset;
u8 reg[CACHE_NR_REGS];
@@ -151,15 +149,21 @@ static void sprd_pmic_eic_irq_mask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip);
+ u32 offset = irqd_to_hwirq(data);

pmic_eic->reg[REG_IE] = 0;
pmic_eic->reg[REG_TRIG] = 0;
+
+ gpiochip_disable_irq(chip, offset);
}

static void sprd_pmic_eic_irq_unmask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip);
+ u32 offset = irqd_to_hwirq(data);
+
+ gpiochip_enable_irq(chip, offset);

pmic_eic->reg[REG_IE] = 1;
pmic_eic->reg[REG_TRIG] = 1;
@@ -292,6 +296,17 @@ static irqreturn_t sprd_pmic_eic_irq_handler(int irq, void *data)
return IRQ_HANDLED;
}

+static const struct irq_chip pmic_eic_irq_chip = {
+ .name = "sprd-pmic-eic",
+ .irq_mask = sprd_pmic_eic_irq_mask,
+ .irq_unmask = sprd_pmic_eic_irq_unmask,
+ .irq_set_type = sprd_pmic_eic_irq_set_type,
+ .irq_bus_lock = sprd_pmic_eic_bus_lock,
+ .irq_bus_sync_unlock = sprd_pmic_eic_bus_sync_unlock,
+ .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};
+
static int sprd_pmic_eic_probe(struct platform_device *pdev)
{
struct gpio_irq_chip *irq;
@@ -338,16 +353,8 @@ static int sprd_pmic_eic_probe(struct platform_device *pdev)
pmic_eic->chip.set = sprd_pmic_eic_set;
pmic_eic->chip.get = sprd_pmic_eic_get;

- pmic_eic->intc.name = dev_name(&pdev->dev);
- pmic_eic->intc.irq_mask = sprd_pmic_eic_irq_mask;
- pmic_eic->intc.irq_unmask = sprd_pmic_eic_irq_unmask;
- pmic_eic->intc.irq_set_type = sprd_pmic_eic_irq_set_type;
- pmic_eic->intc.irq_bus_lock = sprd_pmic_eic_bus_lock;
- pmic_eic->intc.irq_bus_sync_unlock = sprd_pmic_eic_bus_sync_unlock;
- pmic_eic->intc.flags = IRQCHIP_SKIP_SET_WAKE;
-
irq = &pmic_eic->chip.irq;
- irq->chip = &pmic_eic->intc;
+ gpio_irq_chip_set_chip(irq, &pmic_eic_irq_chip);
irq->threaded = true;

ret = devm_gpiochip_add_data(&pdev->dev, &pmic_eic->chip, pmic_eic);
--
2.34.1

2022-12-29 15:50:57

by Cixi Geng

[permalink] [raw]
Subject: [PATCH V4 3/3] gpio: gpio-sprd: Make the irqchip immutable

From: Cixi Geng <[email protected]>

Make the struct irq_chip const, flag it as IRQCHIP_IMMUTABLE, add the
new helper functions, and call the appropriate gpiolib functions.

Signed-off-by: Cixi Geng <[email protected]>
Reported-by: kernel test robot <[email protected]>
Reported-by: Julia Lawall <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
---
drivers/gpio/gpio-sprd.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
index 9bff63990eee..072b4e653216 100644
--- a/drivers/gpio/gpio-sprd.c
+++ b/drivers/gpio/gpio-sprd.c
@@ -120,6 +120,7 @@ static void sprd_gpio_irq_mask(struct irq_data *data)
u32 offset = irqd_to_hwirq(data);

sprd_gpio_update(chip, offset, SPRD_GPIO_IE, 0);
+ gpiochip_disable_irq(chip, offset);
}

static void sprd_gpio_irq_ack(struct irq_data *data)
@@ -136,6 +137,7 @@ static void sprd_gpio_irq_unmask(struct irq_data *data)
u32 offset = irqd_to_hwirq(data);

sprd_gpio_update(chip, offset, SPRD_GPIO_IE, 1);
+ gpiochip_enable_irq(chip, offset);
}

static int sprd_gpio_irq_set_type(struct irq_data *data,
@@ -205,13 +207,14 @@ static void sprd_gpio_irq_handler(struct irq_desc *desc)
chained_irq_exit(ic, desc);
}

-static struct irq_chip sprd_gpio_irqchip = {
+static const struct irq_chip sprd_gpio_irqchip = {
.name = "sprd-gpio",
.irq_ack = sprd_gpio_irq_ack,
.irq_mask = sprd_gpio_irq_mask,
.irq_unmask = sprd_gpio_irq_unmask,
.irq_set_type = sprd_gpio_irq_set_type,
- .flags = IRQCHIP_SKIP_SET_WAKE,
+ .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
+ GPIOCHIP_IRQ_RESOURCE_HELPERS,
};

static int sprd_gpio_probe(struct platform_device *pdev)
@@ -245,7 +248,7 @@ static int sprd_gpio_probe(struct platform_device *pdev)
sprd_gpio->chip.direction_output = sprd_gpio_direction_output;

irq = &sprd_gpio->chip.irq;
- irq->chip = &sprd_gpio_irqchip;
+ gpio_irq_chip_set_chip(irq, &sprd_gpio_irqchip);
irq->handler = handle_bad_irq;
irq->default_type = IRQ_TYPE_NONE;
irq->parent_handler = sprd_gpio_irq_handler;
--
2.34.1

2022-12-30 16:04:59

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH V4 0/3] Make the irqchip immutable

On Thu, Dec 29, 2022 at 3:56 PM Cixi Geng <[email protected]> wrote:
>
> From: Cixi Geng <[email protected]>
>
> Kernel warns about mutable irq_chips:
> "not an immutable chip, please consider fixing!"
>
> Make the struct irq_chip const, flag it as IRQCHIP_IMMUTABLE, add the
> new helper functions, and call the appropriate gpiolib functions.
>
> v2 changes:
> Split the patch by each driver. and other comment by baolin in[1]
>
> v3 changes:
> Fix cocci warnings test by lkp[2].
>
> v4 changes:
> Change the irq name.
> Keep the same coding style by using offset for irqd_to_hwirq(data)
> Add Reviewed-by tag.
>
> [1]:https://lore.kernel.org/all/[email protected]/
> [2]:https://lore.kernel.org/all/[email protected]/
>
> Cixi Geng (3):
> gpio: eic-sprd: Make the irqchip immutable
> gpio: gpio-pmic-eic-sprd: Make the irqchip immutable
> gpio: gpio-sprd: Make the irqchip immutable
>
> drivers/gpio/gpio-eic-sprd.c | 23 ++++++++++++++---------
> drivers/gpio/gpio-pmic-eic-sprd.c | 29 ++++++++++++++++++-----------
> drivers/gpio/gpio-sprd.c | 9 ++++++---
> 3 files changed, 38 insertions(+), 23 deletions(-)
>
>
> base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2
> --
> 2.34.1
>

Series queued for fixes, thanks!

Bart