2022-08-15 07:16:31

by Dan Carpenter

[permalink] [raw]
Subject: drivers/irqchip/irq-stm32-exti.c:719 stm32_exti_h_domain_alloc() warn: variable dereferenced before check 'host_data->drv_data' (see line 707)

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 69dac8e431af26173ca0a1ebc87054e01c585bcc
commit: c297493336b7bc0c12ced484a9e61d04ec2d9403 irqchip/stm32-exti: Simplify irq description table
config: arm-randconfig-m041-20220812 (https://download.01.org/0day-ci/archive/20220813/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
drivers/irqchip/irq-stm32-exti.c:719 stm32_exti_h_domain_alloc() warn: variable dereferenced before check 'host_data->drv_data' (see line 707)

vim +719 drivers/irqchip/irq-stm32-exti.c

927abfc4461e7fd7 Ludovic Barre 2018-04-26 692 static int stm32_exti_h_domain_alloc(struct irq_domain *dm,
927abfc4461e7fd7 Ludovic Barre 2018-04-26 693 unsigned int virq,
927abfc4461e7fd7 Ludovic Barre 2018-04-26 694 unsigned int nr_irqs, void *data)
927abfc4461e7fd7 Ludovic Barre 2018-04-26 695 {
927abfc4461e7fd7 Ludovic Barre 2018-04-26 696 struct stm32_exti_host_data *host_data = dm->host_data;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 697 struct stm32_exti_chip_data *chip_data;
c297493336b7bc0c Antonio Borneo 2022-06-06 698 u8 desc_irq;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 699 struct irq_fwspec *fwspec = data;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 700 struct irq_fwspec p_fwspec;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 701 irq_hw_number_t hwirq;
9d6a5fe1757cbbd9 Alexandre Torgue 2020-07-17 702 int bank;
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 703 u32 event_trg;
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 704 struct irq_chip *chip;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 705
927abfc4461e7fd7 Ludovic Barre 2018-04-26 706 hwirq = fwspec->param[0];
c16ae609214e8356 Antonio Borneo 2022-06-06 @707 if (hwirq >= host_data->drv_data->bank_nr * IRQS_PER_BANK)
^^^^^^^^^^^^^^^^^^^^^
derefernce

c16ae609214e8356 Antonio Borneo 2022-06-06 708 return -EINVAL;
c16ae609214e8356 Antonio Borneo 2022-06-06 709
927abfc4461e7fd7 Ludovic Barre 2018-04-26 710 bank = hwirq / IRQS_PER_BANK;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 711 chip_data = &host_data->chips_data[bank];
927abfc4461e7fd7 Ludovic Barre 2018-04-26 712
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 713 event_trg = readl_relaxed(host_data->base + chip_data->reg_bank->trg_ofst);
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 714 chip = (event_trg & BIT(hwirq % IRQS_PER_BANK)) ?
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 715 &stm32_exti_h_chip : &stm32_exti_h_chip_direct;
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 716
ce4ef8f9f2abcf10 Antonio Borneo 2022-06-06 717 irq_domain_set_hwirq_and_chip(dm, virq, hwirq, chip, chip_data);
c297493336b7bc0c Antonio Borneo 2022-06-06 718
c297493336b7bc0c Antonio Borneo 2022-06-06 @719 if (!host_data->drv_data || !host_data->drv_data->desc_irqs)
^^^^^^^^^^^^^^^^^^^
checked too late

c297493336b7bc0c Antonio Borneo 2022-06-06 720 return -EINVAL;
c297493336b7bc0c Antonio Borneo 2022-06-06 721
c297493336b7bc0c Antonio Borneo 2022-06-06 722 desc_irq = host_data->drv_data->desc_irqs[hwirq];
c297493336b7bc0c Antonio Borneo 2022-06-06 723 if (desc_irq != EXTI_INVALID_IRQ) {
927abfc4461e7fd7 Ludovic Barre 2018-04-26 724 p_fwspec.fwnode = dm->parent->fwnode;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 725 p_fwspec.param_count = 3;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 726 p_fwspec.param[0] = GIC_SPI;
c297493336b7bc0c Antonio Borneo 2022-06-06 727 p_fwspec.param[1] = desc_irq;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 728 p_fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 729
927abfc4461e7fd7 Ludovic Barre 2018-04-26 730 return irq_domain_alloc_irqs_parent(dm, virq, 1, &p_fwspec);
927abfc4461e7fd7 Ludovic Barre 2018-04-26 731 }
927abfc4461e7fd7 Ludovic Barre 2018-04-26 732
927abfc4461e7fd7 Ludovic Barre 2018-04-26 733 return 0;
927abfc4461e7fd7 Ludovic Barre 2018-04-26 734 }

--
0-DAY CI Kernel Test Service
https://01.org/lkp


2022-08-17 13:05:50

by Antonio Borneo

[permalink] [raw]
Subject: [PATCH] irqchip/stm32-exti: Remove check on always false condition

The field drv_data is assigned during driver's probe, where it's
already checked to be not NULL.

Remove the always false check '!host_data->drv_data'.

This fixes a warning "variable dereferenced before check" detected
by '0-DAY CI Kernel Test Service'.

Fixes: c297493336b7 ("irqchip/stm32-exti: Simplify irq description table")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Antonio Borneo <[email protected]>
---
drivers/irqchip/irq-stm32-exti.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
index a73763d475f0..6a3f7498ea8e 100644
--- a/drivers/irqchip/irq-stm32-exti.c
+++ b/drivers/irqchip/irq-stm32-exti.c
@@ -716,7 +716,7 @@ static int stm32_exti_h_domain_alloc(struct irq_domain *dm,

irq_domain_set_hwirq_and_chip(dm, virq, hwirq, chip, chip_data);

- if (!host_data->drv_data || !host_data->drv_data->desc_irqs)
+ if (!host_data->drv_data->desc_irqs)
return -EINVAL;

desc_irq = host_data->drv_data->desc_irqs[hwirq];

base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
--
2.25.1

2022-08-17 14:01:38

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [irqchip: irq/irqchip-fixes] irqchip/stm32-exti: Remove check on always false condition

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID: c3e88d91e40971337d4e7b5250e9e17d3e64238c
Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/c3e88d91e40971337d4e7b5250e9e17d3e64238c
Author: Antonio Borneo <[email protected]>
AuthorDate: Wed, 17 Aug 2022 14:57:58 +02:00
Committer: Marc Zyngier <[email protected]>
CommitterDate: Wed, 17 Aug 2022 14:19:48 +01:00

irqchip/stm32-exti: Remove check on always false condition

The field drv_data is assigned during driver's probe, where it's
already checked to be not NULL.

Remove the always false check '!host_data->drv_data'.

This fixes a warning "variable dereferenced before check" detected
by '0-DAY CI Kernel Test Service'.

Fixes: c297493336b7 ("irqchip/stm32-exti: Simplify irq description table")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Antonio Borneo <[email protected]>
Signed-off-by: Marc Zyngier <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
drivers/irqchip/irq-stm32-exti.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
index a73763d..6a3f749 100644
--- a/drivers/irqchip/irq-stm32-exti.c
+++ b/drivers/irqchip/irq-stm32-exti.c
@@ -716,7 +716,7 @@ static int stm32_exti_h_domain_alloc(struct irq_domain *dm,

irq_domain_set_hwirq_and_chip(dm, virq, hwirq, chip, chip_data);

- if (!host_data->drv_data || !host_data->drv_data->desc_irqs)
+ if (!host_data->drv_data->desc_irqs)
return -EINVAL;

desc_irq = host_data->drv_data->desc_irqs[hwirq];

2022-09-13 13:29:05

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [irqchip: irq/irqchip-fixes] irqchip/stm32-exti: Remove check on always false condition

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID: 8fc7a6198a80bc39b6c5b3cc1a578e7d24f068a2
Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/8fc7a6198a80bc39b6c5b3cc1a578e7d24f068a2
Author: Antonio Borneo <[email protected]>
AuthorDate: Wed, 17 Aug 2022 14:57:58 +02:00
Committer: Marc Zyngier <[email protected]>
CommitterDate: Mon, 12 Sep 2022 16:31:25 +01:00

irqchip/stm32-exti: Remove check on always false condition

The field drv_data is assigned during driver's probe, where it's
already checked to be not NULL.

Remove the always false check '!host_data->drv_data'.

This fixes a warning "variable dereferenced before check" detected
by '0-DAY CI Kernel Test Service'.

Fixes: c297493336b7 ("irqchip/stm32-exti: Simplify irq description table")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Antonio Borneo <[email protected]>
Signed-off-by: Marc Zyngier <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
drivers/irqchip/irq-stm32-exti.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c
index a73763d..6a3f749 100644
--- a/drivers/irqchip/irq-stm32-exti.c
+++ b/drivers/irqchip/irq-stm32-exti.c
@@ -716,7 +716,7 @@ static int stm32_exti_h_domain_alloc(struct irq_domain *dm,

irq_domain_set_hwirq_and_chip(dm, virq, hwirq, chip, chip_data);

- if (!host_data->drv_data || !host_data->drv_data->desc_irqs)
+ if (!host_data->drv_data->desc_irqs)
return -EINVAL;

desc_irq = host_data->drv_data->desc_irqs[hwirq];