linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
@ 2020-12-21 14:30 John Garry
  2020-12-22  8:12 ` [irqchip: irq/irqchip-next] driver " irqchip-bot for John Garry
  2021-01-08 15:43 ` [PATCH] Driver " Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: John Garry @ 2020-12-21 14:30 UTC (permalink / raw)
  To: gregkh, rafael, maz, tglx; +Cc: linux-kernel, dan.carpenter, John Garry

The current check of nvec < minvec for nvec returned from
platform_irq_count() will not detect a negative error code in nvec.

This is because minvec is unsigned, and, as such, nvec is promoted to
unsigned in that check, which will make it a huge number (if it contained
-EPROBE_DEFER).

In practice, an error should not occur in nvec for the only in-tree
user, but add a check anyway.

Fixes: e15f2fa959f2 ("driver core: platform: Add devm_platform_get_irqs_affinity()")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: John Garry <john.garry@huawei.com>
---
I hope that this can go through either irqchip or driver/core trees, thanks!

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 95fd1549f87d..8456d8384ac8 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -366,6 +366,8 @@ int devm_platform_get_irqs_affinity(struct platform_device *dev,
 		return -ERANGE;
 
 	nvec = platform_irq_count(dev);
+	if (nvec < 0)
+		return nvec;
 
 	if (nvec < minvec)
 		return -ENOSPC;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [irqchip: irq/irqchip-next] driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
  2020-12-21 14:30 [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity() John Garry
@ 2020-12-22  8:12 ` irqchip-bot for John Garry
  2021-01-08 15:43 ` [PATCH] Driver " Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: irqchip-bot for John Garry @ 2020-12-22  8:12 UTC (permalink / raw)
  To: linux-kernel; +Cc: Dan Carpenter, John Garry, Marc Zyngier, tglx

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

Commit-ID:     e1dc20995cb9fa04b46e8f37113a7203c906d2bf
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/e1dc20995cb9fa04b46e8f37113a7203c906d2bf
Author:        John Garry <john.garry@huawei.com>
AuthorDate:    Mon, 21 Dec 2020 22:30:55 +08:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Tue, 22 Dec 2020 08:06:38 

driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()

The current check of nvec < minvec for nvec returned from
platform_irq_count() will not detect a negative error code in nvec.

This is because minvec is unsigned, and, as such, nvec is promoted to
unsigned in that check, which will make it a huge number (if it contained
-EPROBE_DEFER).

In practice, an error should not occur in nvec for the only in-tree
user, but add a check anyway.

Fixes: e15f2fa959f2 ("driver core: platform: Add devm_platform_get_irqs_affinity()")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/1608561055-231244-1-git-send-email-john.garry@huawei.com
---
 drivers/base/platform.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ea8add1..74c97b6 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -351,6 +351,8 @@ int devm_platform_get_irqs_affinity(struct platform_device *dev,
 		return -ERANGE;
 
 	nvec = platform_irq_count(dev);
+	if (nvec < 0)
+		return nvec;
 
 	if (nvec < minvec)
 		return -ENOSPC;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
  2021-01-08 15:43 ` [PATCH] Driver " Greg KH
@ 2021-01-08 15:43   ` John Garry
  2021-01-08 15:48     ` Marc Zyngier
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2021-01-08 15:43 UTC (permalink / raw)
  To: Greg KH; +Cc: rafael, maz, tglx, linux-kernel, dan.carpenter

On 08/01/2021 15:43, Greg KH wrote:
> On Mon, Dec 21, 2020 at 10:30:55PM +0800, John Garry wrote:
>> The current check of nvec < minvec for nvec returned from
>> platform_irq_count() will not detect a negative error code in nvec.
>>
>> This is because minvec is unsigned, and, as such, nvec is promoted to
>> unsigned in that check, which will make it a huge number (if it contained
>> -EPROBE_DEFER).
>>
>> In practice, an error should not occur in nvec for the only in-tree
>> user, but add a check anyway.
>>
>> Fixes: e15f2fa959f2 ("driver core: platform: Add devm_platform_get_irqs_affinity()")
>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>> Signed-off-by: John Garry <john.garry@huawei.com>
>> ---
>> I hope that this can go through either irqchip or driver/core trees, thanks!
> 
> I'll take it, thanks.
> 

Hi Greg,

I think that Marc already has taken it:

https://lore.kernel.org/lkml/X%2Fh9vy%2F1h0E1hyN0@kroah.com/T/#m95ef1736dbbd801cd85a4144c8f13c2afe33bc2c

I hope it doesn't cause hassle.

Thanks,
John


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
  2020-12-21 14:30 [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity() John Garry
  2020-12-22  8:12 ` [irqchip: irq/irqchip-next] driver " irqchip-bot for John Garry
@ 2021-01-08 15:43 ` Greg KH
  2021-01-08 15:43   ` John Garry
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2021-01-08 15:43 UTC (permalink / raw)
  To: John Garry; +Cc: rafael, maz, tglx, linux-kernel, dan.carpenter

On Mon, Dec 21, 2020 at 10:30:55PM +0800, John Garry wrote:
> The current check of nvec < minvec for nvec returned from
> platform_irq_count() will not detect a negative error code in nvec.
> 
> This is because minvec is unsigned, and, as such, nvec is promoted to
> unsigned in that check, which will make it a huge number (if it contained
> -EPROBE_DEFER).
> 
> In practice, an error should not occur in nvec for the only in-tree
> user, but add a check anyway.
> 
> Fixes: e15f2fa959f2 ("driver core: platform: Add devm_platform_get_irqs_affinity()")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
> I hope that this can go through either irqchip or driver/core trees, thanks!

I'll take it, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
  2021-01-08 15:43   ` John Garry
@ 2021-01-08 15:48     ` Marc Zyngier
  2021-01-08 16:06       ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2021-01-08 15:48 UTC (permalink / raw)
  To: John Garry; +Cc: Greg KH, rafael, tglx, linux-kernel, dan.carpenter

On 2021-01-08 15:43, John Garry wrote:
> On 08/01/2021 15:43, Greg KH wrote:
>> On Mon, Dec 21, 2020 at 10:30:55PM +0800, John Garry wrote:
>>> The current check of nvec < minvec for nvec returned from
>>> platform_irq_count() will not detect a negative error code in nvec.
>>> 
>>> This is because minvec is unsigned, and, as such, nvec is promoted to
>>> unsigned in that check, which will make it a huge number (if it 
>>> contained
>>> -EPROBE_DEFER).
>>> 
>>> In practice, an error should not occur in nvec for the only in-tree
>>> user, but add a check anyway.
>>> 
>>> Fixes: e15f2fa959f2 ("driver core: platform: Add 
>>> devm_platform_get_irqs_affinity()")
>>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> Signed-off-by: John Garry <john.garry@huawei.com>
>>> ---
>>> I hope that this can go through either irqchip or driver/core trees, 
>>> thanks!
>> 
>> I'll take it, thanks.
>> 
> 
> Hi Greg,
> 
> I think that Marc already has taken it:
> 
> https://lore.kernel.org/lkml/X%2Fh9vy%2F1h0E1hyN0@kroah.com/T/#m95ef1736dbbd801cd85a4144c8f13c2afe33bc2c
> 
> I hope it doesn't cause hassle.

I was about to send tglx a pull request.

Greg, let me know if you want me to drop it.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
  2021-01-08 15:48     ` Marc Zyngier
@ 2021-01-08 16:06       ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-01-08 16:06 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: John Garry, rafael, tglx, linux-kernel, dan.carpenter

On Fri, Jan 08, 2021 at 03:48:24PM +0000, Marc Zyngier wrote:
> On 2021-01-08 15:43, John Garry wrote:
> > On 08/01/2021 15:43, Greg KH wrote:
> > > On Mon, Dec 21, 2020 at 10:30:55PM +0800, John Garry wrote:
> > > > The current check of nvec < minvec for nvec returned from
> > > > platform_irq_count() will not detect a negative error code in nvec.
> > > > 
> > > > This is because minvec is unsigned, and, as such, nvec is promoted to
> > > > unsigned in that check, which will make it a huge number (if it
> > > > contained
> > > > -EPROBE_DEFER).
> > > > 
> > > > In practice, an error should not occur in nvec for the only in-tree
> > > > user, but add a check anyway.
> > > > 
> > > > Fixes: e15f2fa959f2 ("driver core: platform: Add
> > > > devm_platform_get_irqs_affinity()")
> > > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > > Signed-off-by: John Garry <john.garry@huawei.com>
> > > > ---
> > > > I hope that this can go through either irqchip or driver/core
> > > > trees, thanks!
> > > 
> > > I'll take it, thanks.
> > > 
> > 
> > Hi Greg,
> > 
> > I think that Marc already has taken it:
> > 
> > https://lore.kernel.org/lkml/X%2Fh9vy%2F1h0E1hyN0@kroah.com/T/#m95ef1736dbbd801cd85a4144c8f13c2afe33bc2c
> > 
> > I hope it doesn't cause hassle.
> 
> I was about to send tglx a pull request.
> 
> Greg, let me know if you want me to drop it.

Nope, no worries, git will handle this coming in multiple places :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-08 16:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 14:30 [PATCH] Driver core: platform: Add extra error check in devm_platform_get_irqs_affinity() John Garry
2020-12-22  8:12 ` [irqchip: irq/irqchip-next] driver " irqchip-bot for John Garry
2021-01-08 15:43 ` [PATCH] Driver " Greg KH
2021-01-08 15:43   ` John Garry
2021-01-08 15:48     ` Marc Zyngier
2021-01-08 16:06       ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).