tpm: clean up error checking in setup_ring()
Subsystems (3)
PATCH 1/1 tpm: clean up error checking in setup_ring()
The bind_evtchn_to_irqhandler() function can never return 0. Historically, IRQ functions used to return zero on error, but then we added an architecture where that was a valid IRQ so it went from being an error to being success (but in a limitted way, just enough for that arch to boot, I guess). Eventually we removed it and we will never allow zero to be a valid IRQ again.
The problem here is that if zero were an invalid IRQ then we should return a negative error code but the code returns zero/success.
Change the code to check for negative error codes so it's not question of how the zero should be handled.
---
From static analysis. Untested.
drivers/char/tpm/xen-tpmfront.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/xen-tpmfront.c +1 -1
@@ -266,7 +266,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv) rv =bind_evtchn_to_irqhandler (priv->evtchn, tpmif_interrupt,0 ,"tpmif" , priv); -if (rv <=0 ) { +if (rv <0 ) {xenbus_dev_fatal (dev, rv,"allocating TPM irq" );return rv; }
Signature · 1 line
2.53.0
Jarkko Sakkinen
maintainerQuoted 36 lines · Dan Carpenter
The
bind_evtchn_to_irqhandler()function can never return 0. Historically, IRQ functions used to return zero on error, but then we added an architecture where that was a valid IRQ so it went from being an error to being success (but in a limitted way, just enough for that arch to boot, I guess). Eventually we removed it and we will never allow zero to be a valid IRQ again.The problem here is that if zero were an invalid IRQ then we should return a negative error code but the code returns zero/success.
Change the code to check for negative error codes so it's not question of how the zero should be handled.
Signed-off-by Dan Carpenter <[email protected]>---
From static analysis. Untested.drivers/char/tpm/xen-tpmfront.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/tpm/xen-tpmfront.c +1
-1@@ -266,7 +266,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv) rv =bind_evtchn_to_irqhandler (priv->evtchn, tpmif_interrupt,0 ,"tpmif" , priv); -if (rv <=0 ) { +if (rv <0 ) {xenbus_dev_fatal (dev, rv,"allocating TPM irq" );return rv; }Signature · 1 line
2.53.0
Looks good to me. Isn't this a bug by definition?
Br, Jarkko
Quoted 36 lines · Dan Carpenter
The
bind_evtchn_to_irqhandler()function can never return 0. Historically, IRQ functions used to return zero on error, but then we added an architecture where that was a valid IRQ so it went from being an error to being success (but in a limitted way, just enough for that arch to boot, I guess). Eventually we removed it and we will never allow zero to be a valid IRQ again.The problem here is that if zero were an invalid IRQ then we should return a negative error code but the code returns zero/success.
Change the code to check for negative error codes so it's not question of how the zero should be handled.
Signed-off-by Dan Carpenter <[email protected]>---
From static analysis. Untested.drivers/char/tpm/xen-tpmfront.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/tpm/xen-tpmfront.c +1
-1@@ -266,7 +266,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv) rv =bind_evtchn_to_irqhandler (priv->evtchn, tpmif_interrupt,0 ,"tpmif" , priv); -if (rv <=0 ) { +if (rv <0 ) {xenbus_dev_fatal (dev, rv,"allocating TPM irq" );return rv; }Signature · 1 line
2.53.0
Sorry if responded to this already. Mutt shows this responded but cannot find it from lore.
Anyway,
Br, Jarkko
Quoted 1 line
The
bind_evtchn_to_irqhandler()function can never return 0.
…
I suggest to reconsider information once more also according to the probability of return values from such a function.
https://elixir.bootlin.com/linux/v7.3-rc6/source/drivers/xen/events/events_base.c#L1453-L1461
bind_evtchn_to_irqhandler_chip()
https://elixir.bootlin.com/linux/v7.3-rc6/source/drivers/xen/events/events_base.c#L1432-L1451
…
Quoted 4 lines
---
From static analysis. Untested.drivers/char/tpm/xen-tpmfront.c | 2 +-
…
Would you be looking for further collateral evolution?
https://elixir.bootlin.com/linux/v7.3-rc6/source/drivers/char/tpm/xen-tpmfront.c#L267-L272
Regards,
Markus
Jarkko Sakkinen
maintainerQuoted 9 lines · Markus Elfring
Quoted 1 line
The
bind_evtchn_to_irqhandler()function can never return 0.…
I suggest to reconsider information once more also according to the probability of return values from such a function.
https://elixir.bootlin.com/linux/v7.3-rc6/source/drivers/xen/events/events_base.c#L1453-L1461
bind_evtchn_to_irqhandler_chip()
https://elixir.bootlin.com/linux/v7.3-rc6/source/drivers/xen/events/events_base.c#L1432-L1451
I'm not sure what you are trying to exactly or have hard time following this response but if there is a problem it can be investigated. All I'm seeing now is a collection of links and abstract statements.
I guess this is the function that picks the IRQ number:
static struct irq_info *xen_allocate_irq_dynamic(void)
{
int irq = irq_alloc_desc_from(0, -1);
struct irq_info *info = NULL;
if (irq >= 0) {
info = xen_irq_init(irq);
if (!info)
xen_irq_free_desc(irq);
}
return info;
}And if I did not get loss while scavenging the call hierachy it ends up to:
static int irq_find_free_area(unsigned int from, unsigned int cnt)
{
MA_STATE(mas, &sparse_irqs, 0, 0);
if (mas_empty_area(&mas, from, MAX_SPARSE_IRQS, cnt))
return -ENOSPC;
return mas.index;
}And if I looked it up right @from == -1 and @cnt == 1 when irq_find_free_area is reached.
I'm not IRQ code expert per se but in order to this never return zero, sparse_irqs should not have it available?
I do agree that something in this patch does not appear right, or at least not very well explained so it is a good catch anyhow.
My decision on this is that:
1. I'll drop the current patch as it actually does not make a case why zero could not possibly happen. I spent 45 minutes browsing because commit message did not have any technical details.
2. Even if it was legit it is hard to see that the change is high priority for anyone.
3. However, I'm open for v2 with better tecnical backing if there is any.
Br, Jarkko
Quoted 1 line
Quoted 1 line
Quoted 1 line
The
bind_evtchn_to_irqhandler()function can never return 0.
…
Quoted 8 lines
I do agree that something in this patch does not appear right, or at least not very well explained so it is a good catch anyhow.
My decision on this is that:
1. I'll drop the current patch as it actually does not make a case why zero could not possibly happen. I spent 45 minutes browsing because commit message did not have any technical details.…
How does this response fit to your previous tag “Reviewed-by”?
Dan Carpenter provided also some hints.
Regards,
Markus
Jarkko Sakkinen
maintainerQuoted 7 lines · Markus Elfring
Quoted 1 line
Quoted 1 line
Quoted 1 line
The
bind_evtchn_to_irqhandler()function can never return 0.…
Quoted 5 lines
I do agree that something in this patch does not appear right, or at least not very well explained so it is a good catch anyhow.
My decision on this is that:
Quoted 7 lines
Quoted 3 lines
1. I'll drop the current patch as it actually does not make a case why zero could not possibly happen. I spent 45 minutes browsing because commit message did not have any technical details.…
How does this response fit to your previous tag “Reviewed-by”?
Dan Carpenter provided also some hints.
There's no problem with this. I sanity checked the commit because I did not (and do not) understand what you wrote, and started to check up on things because of that email.
I came into conclusion that the commit message does not nail down its claim well enough so I did the only common sense action one can do in this situation.
Quoted 3 lines
Regards,
Markus
Br, Jarkko
…
Quoted 4 lines
Quoted 1 line
Dan Carpenter provided also some hints.
There's no problem with this. I sanity checked the commit because I did not (and do not) understand what you wrote,
Is there a need to clarify remaining communication difficulties any further?
Quoted 2 lines
and started to
check up on things because of that email.…
Thanks.
Regards,
Markus