driver core: platform: Add extra error check in devm_platform_get_irqs_affinity()
authorJohn Garry <john.garry@huawei.com>
Mon, 21 Dec 2020 14:30:55 +0000 (22:30 +0800)
committerMarc Zyngier <maz@kernel.org>
Tue, 22 Dec 2020 08:06:38 +0000 (08:06 +0000)
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

index ea8add1..74c97b6 100644 (file)
@@ -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;