Skip to contentSkip to conversation

mailbox: qcom-ipcc: fix error reporting paths

PATCH In review Gabriele Paoloni 3 participants 10 messages Mar 16 – Mar 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover mailbox: qcom-ipcc: fix error reporting paths

This patchset implements a couple of fixes to ensure errors being properly reported in the qcom-ipcc driver.

Thanks
Gab

Gabriele Paoloni (2):
mailbox: qcom-ipcc: amend qcom_ipcc_domain_map() to report errors
mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

 drivers/mailbox/qcom-ipcc.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/2 mailbox: qcom-ipcc: amend qcom_ipcc_domain_map() to report errors

Currently qcom_ipcc_domain_map() ignores errors returned by irq_set_chip_data() and invokes irq_set_chip_and_handler() that in turn ignores errors returned by irq_set_chip(). This patch fixes both issues; no other functional changes are implemented.

---
 drivers/mailbox/qcom-ipcc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mailbox/qcom-ipcc.c +11 -3
index d957d989c0ce..c23efaaa64a1 100644
@@ -116,12 +116,20 @@ static struct irq_chip qcom_ipcc_irq_chip = {
 static int qcom_ipcc_domain_map(struct irq_domain *d, unsigned int irq,
 				irq_hw_number_t hw)
 {
+	int ret;
 	struct qcom_ipcc *ipcc = d->host_data;
 
-	irq_set_chip_and_handler(irq, &qcom_ipcc_irq_chip, handle_level_irq);
-	irq_set_chip_data(irq, ipcc);
-	irq_set_noprobe(irq);
+	ret = irq_set_chip(irq, &qcom_ipcc_irq_chip);
+	if (ret)
+		return ret;
+
+	irq_set_handler(irq, handle_level_irq);
 
+	ret = irq_set_chip_data(irq, ipcc);
+	if (ret)
+		return ret;
+
+	irq_set_noprobe(irq);
 	return 0;
 }
 
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH 1/2] mailbox: qcom-ipcc: amend qcom_ipcc_domain_map() to report errors

Quoted 16 lines · Gabriele Paoloni

Currently qcom_ipcc_domain_map() ignores errors returned by irq_set_chip_data() and invokes irq_set_chip_and_handler() that in turn ignores errors returned by irq_set_chip(). This patch fixes both issues; no other functional changes are implemented.

---
 drivers/mailbox/qcom-ipcc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/mailbox/qcom-ipcc.c +0 -0
index d957d989c0ce..c23efaaa64a1 100644

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 120

Quoted 5 lines
drivers/mailbox/qcom-ipcc.c +1 -0
@@ -116,12 +116,20 @@ static struct irq_chip qcom_ipcc_irq_chip = {
 static int qcom_ipcc_domain_map(struct irq_domain *d, unsigned int irq,
 				irq_hw_number_t hw)
 {
+	int ret;
 	struct qcom_ipcc *ipcc = d->host_data;

Put variables in reverse Christmas tree order.

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 121

Quoted 2 lines
drivers/mailbox/qcom-ipcc.c +0 -1
-	irq_set_chip_and_handler(irq, &qcom_ipcc_irq_chip, handle_level_irq);

Should irq_set_chip_and_handler() and irq_set_chip_and_handler_name() be updated to return an int to reduce boiler plate code?

Quoted 4 lines
drivers/mailbox/qcom-ipcc.c +2 -2
-	irq_set_chip_data(irq, ipcc);
-	irq_set_noprobe(irq);
+	ret = irq_set_chip(irq, &qcom_ipcc_irq_chip);
+	if (ret)

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 133

Quoted 10 lines
drivers/mailbox/qcom-ipcc.c +8 -0
+		return ret;
+
+	irq_set_handler(irq, handle_level_irq);
 
+	ret = irq_set_chip_data(irq, ipcc);
+	if (ret)
+		return ret;
+
+	irq_set_noprobe(irq);
 	return 0;

The newline before the return 0 is removed. That should also remove the irq_set_noprobe() change from the diffstat.

Brian

#3 lore raw

Re: [PATCH 1/2] mailbox: qcom-ipcc: amend qcom_ipcc_domain_map() to report errors

Quoted 13 lines · Brian Masney
Quoted 11 lines · Gabriele Paoloni

Currently qcom_ipcc_domain_map() ignores errors returned by irq_set_chip_data() and invokes irq_set_chip_and_handler() that in turn ignores errors returned by irq_set_chip(). This patch fixes both issues; no other functional changes are implemented.

---
 drivers/mailbox/qcom-ipcc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Quoted 12 lines

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 120

Quoted 10 lines
drivers/mailbox/qcom-ipcc.c +1 -0
index d957d989c0ce..c23efaaa64a1 100644
@@ -116,12 +116,20 @@ static struct irq_chip qcom_ipcc_irq_chip = {
 static int qcom_ipcc_domain_map(struct irq_domain *d, unsigned int irq,
                              irq_hw_number_t hw)
 {
+     int ret;
      struct qcom_ipcc *ipcc = d->host_data;

Put variables in reverse Christmas tree order.

Noted, I'll fix in v2.

Quoted 6 lines

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 121

Quoted 3 lines
drivers/mailbox/qcom-ipcc.c +0 -1
-     irq_set_chip_and_handler(irq, &qcom_ipcc_irq_chip, handle_level_irq);

Should irq_set_chip_and_handler() and irq_set_chip_and_handler_name() be updated to return an int to reduce boiler plate code?

+TO Thomas Gleixner

It may be a possibility. @Thomas do you have any preference in this regard?

Thanks
Gab

Quoted 21 lines
Quoted 5 lines
drivers/mailbox/qcom-ipcc.c +2 -2
-     irq_set_chip_data(irq, ipcc);
-     irq_set_noprobe(irq);
+     ret = irq_set_chip(irq, &qcom_ipcc_irq_chip);
+     if (ret)

drivers/mailbox/qcom-ipcc.c static struct irq_chip qcom_ipcc_irq_chip = { · line 133

Quoted 10 lines
drivers/mailbox/qcom-ipcc.c +8 -0
+             return ret;
+
+     irq_set_handler(irq, handle_level_irq);
 
+     ret = irq_set_chip_data(irq, ipcc);
+     if (ret)
+             return ret;
+
+     irq_set_noprobe(irq);
      return 0;

The newline before the return 0 is removed. That should also remove the irq_set_noprobe() change from the diffstat.

Brian

#4 lore raw

PATCH 2/2 mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

In reply to Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---
 drivers/mailbox/qcom-ipcc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mailbox/qcom-ipcc.c +8 -2
index c23efaaa64a1..0795184591f0 100644
@@ -75,7 +75,7 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
 {
 	struct qcom_ipcc *ipcc = data;
 	u32 hwirq;
-	int virq;
+	int virq, ret;
 
 	for (;;) {
 		hwirq = readl(ipcc->base + IPCC_REG_RECV_ID);
@@ -83,8 +83,14 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
 			break;
 
 		virq = irq_find_mapping(ipcc->irq_domain, hwirq);
+		if (unlikely(!virq))
+			return IRQ_NONE;
+
 		writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_CLEAR);
-		generic_handle_irq(virq);
+
+		ret = generic_handle_irq(virq);
+		if (unlikely(ret))
+			return IRQ_NONE;
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
2.48.1
#5 lore raw

Re: [PATCH 2/2] mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

Quoted 14 lines · Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---
 drivers/mailbox/qcom-ipcc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mailbox/qcom-ipcc.c +0 -0
index c23efaaa64a1..0795184591f0 100644

drivers/mailbox/qcom-ipcc.c static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data) · line 78

Quoted 5 lines
drivers/mailbox/qcom-ipcc.c +1 -1
@@ -75,7 +75,7 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
 {
 	struct qcom_ipcc *ipcc = data;
 	u32 hwirq;
-	int virq;
+	int virq, ret;

Put variables in reverse Christmas tree order.

Brian

Quoted 22 lines
drivers/mailbox/qcom-ipcc.c +7 -1
 	for (;;) {
 		hwirq = readl(ipcc->base + IPCC_REG_RECV_ID);
@@ -83,8 +83,14 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
 			break;
 
 		virq = irq_find_mapping(ipcc->irq_domain, hwirq);
+		if (unlikely(!virq))
+			return IRQ_NONE;
+
 		writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_CLEAR);
-		generic_handle_irq(virq);
+
+		ret = generic_handle_irq(virq);
+		if (unlikely(ret))
+			return IRQ_NONE;
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
2.48.1
#6 lore raw

Re: [PATCH 2/2] mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

Quoted 11 lines · Brian Masney
Quoted 9 lines · Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---
 drivers/mailbox/qcom-ipcc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/mailbox/qcom-ipcc.c static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data) · line 78

Quoted 10 lines
drivers/mailbox/qcom-ipcc.c +1 -1
index c23efaaa64a1..0795184591f0 100644
@@ -75,7 +75,7 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
 {
      struct qcom_ipcc *ipcc = data;
      u32 hwirq;
-     int virq;
+     int virq, ret;

Put variables in reverse Christmas tree order.

Note, many thanks. I will fix this in v2

Gab

Quoted 27 lines

Brian

Quoted 22 lines
drivers/mailbox/qcom-ipcc.c +7 -2
      for (;;) {
              hwirq = readl(ipcc->base + IPCC_REG_RECV_ID);
@@ -83,8 +83,14 @@ static irqreturn_t qcom_ipcc_irq_fn(int irq, void *data)
                      break;
 
              virq = irq_find_mapping(ipcc->irq_domain, hwirq);
+             if (unlikely(!virq))
+                     return IRQ_NONE;
+
              writel(hwirq, ipcc->base + IPCC_REG_RECV_SIGNAL_CLEAR);
-             generic_handle_irq(virq);
+
+             ret = generic_handle_irq(virq);
+             if (unlikely(ret))
+                     return IRQ_NONE;
      }
 
      return IRQ_HANDLED;
--

2.48.1

#7 lore raw

Re: [PATCH 2/2] mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

In reply to Gabriele Paoloni
Quoted 6 lines · Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---

It certainly seems useful to inspect a function's return value, however I noticed that out of 47 in-tree callers of generic_handle_irq() within drivers/, only one other driver (intel_lpe_audio within drm/i915) checks that..

Similarly, many other drivers never check if irq_find_mapping() actually succeeded. This makes me wonder how you discovered there's an issue in the first place. Could you please add some details in the commit message?

Konrad

#8 lore raw

Re: [PATCH 2/2] mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

Hi Konrad

Quoted 9 lines · Konrad Dybcio
Quoted 6 lines · Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---

Quoted 8 lines

It certainly seems useful to inspect a function's return value, however I noticed that out of 47 in-tree callers of generic_handle_irq() within drivers/, only one other driver (intel_lpe_audio within drm/i915) checks that..

Similarly, many other drivers never check if irq_find_mapping() actually succeeded. This makes me wonder how you discovered there's an issue in the first place. Could you please add some details in the commit message?

Code inspection spotted the issue, and I could not find a justification for irq_find_mapping() and generic_handle_irq() to always succeed; hence I proposed this patch to follow good coding practices.
However if there is a justification for these functions to always succeed in the context of use of the Qualcomm IPCC driver, I can drop this patch.

Thanks
Gab

Quoted 3 lines

Konrad

Reviewed-by
#9 lore raw

Re: [PATCH 2/2] mailbox: qcom-ipcc: amend qcom_ipcc_irq_fn() to report errors

Quoted 18 lines · Gabriele Paoloni

Hi Konrad

Quoted 14 lines · Konrad Dybcio
Quoted 6 lines · Gabriele Paoloni

check the virq value returned by irq_find_mapping(), also check the return value of generic_handle_irq(); return IRQ_NONE if either of the checks fails.

---

It certainly seems useful to inspect a function's return value, however I noticed that out of 47 in-tree callers of generic_handle_irq() within drivers/, only one other driver (intel_lpe_audio within drm/i915) checks that..

Quoted 7 lines
Quoted 3 lines

Similarly, many other drivers never check if irq_find_mapping() actually succeeded. This makes me wonder how you discovered there's an issue in the first place. Could you please add some details in the commit message?

Code inspection spotted the issue, and I could not find a justification for irq_find_mapping() and generic_handle_irq() to always succeed; hence I proposed this patch to follow good coding practices.

That's a good enough reason

Konrad