2016-10-13 18:15:24

by Tai Nguyen

[permalink] [raw]
Subject: [PATCH v2] perf: xgene: Remove bogus IS_ERR() check

In acpi_get_pmu_hw_inf we pass the address of a local variable to IS_ERR(),
which doesn't make sense, as the pointer must be a real, valid pointer.
This doesn't cause a functional problem, as IS_ERR() will evaluate as
false, but the check is bogus and causes static checkers to complain.

Remove the bogus check.

The bug is reported by Dan Carpenter <[email protected]> in [1]

[1] https://www.spinics.net/lists/arm-kernel/msg535957.html

Signed-off-by: Tai Nguyen <[email protected]>
Acked-by: Mark Rutland <[email protected]>
---
v2:
Add more problem description in the commit message
Add Acked-by: Mark Rutland <[email protected]>

drivers/perf/xgene_pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index c2ac764..a8ac4bc 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -1011,7 +1011,7 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu,
rc = acpi_dev_get_resources(adev, &resource_list,
acpi_pmu_dev_add_resource, &res);
acpi_dev_free_resource_list(&resource_list);
- if (rc < 0 || IS_ERR(&res)) {
+ if (rc < 0) {
dev_err(dev, "PMU type %d: No resource address found\n", type);
goto err;
}
--
1.9.1


2016-10-13 18:18:53

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH v2] perf: xgene: Remove bogus IS_ERR() check

On Thu, Oct 13, 2016 at 11:09:16AM -0700, Tai Nguyen wrote:
> In acpi_get_pmu_hw_inf we pass the address of a local variable to IS_ERR(),
> which doesn't make sense, as the pointer must be a real, valid pointer.
> This doesn't cause a functional problem, as IS_ERR() will evaluate as
> false, but the check is bogus and causes static checkers to complain.

... unless the test is actually a misspelled IS_ERR(res) and the current
code is broken by effectively skipping it.

2016-10-14 00:45:02

by Mark Rutland

[permalink] [raw]
Subject: Re: [PATCH v2] perf: xgene: Remove bogus IS_ERR() check

On Thu, Oct 13, 2016 at 07:18:37PM +0100, Al Viro wrote:
> On Thu, Oct 13, 2016 at 11:09:16AM -0700, Tai Nguyen wrote:
> > In acpi_get_pmu_hw_inf we pass the address of a local variable to IS_ERR(),
> > which doesn't make sense, as the pointer must be a real, valid pointer.
> > This doesn't cause a functional problem, as IS_ERR() will evaluate as
> > false, but the check is bogus and causes static checkers to complain.
>
> ... unless the test is actually a misspelled IS_ERR(res) and the current
> code is broken by effectively skipping it.

Sure.

In this case, res is a struct resource, so IS_ERR(res) is also bogus.

None of the pointer fields in struct resource are ever set to an ERR_PTR value,
so nothing in res is worth checking. Nothing else in the function prior to this
would be an ERR_PTR value either.

I believe this case was copy-paste and a thinko. There's some other error
handling in the file that does validly have to handle an ERR_PTR value.

Thanks,
Mark.