* [PATCH][next] reset: npcm: check for NULL return from syscon_regmap_lookup_by_compat
@ 2019-11-08 15:55 Colin King
2019-11-14 13:22 ` Philipp Zabel
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2019-11-08 15:55 UTC (permalink / raw)
To: Avi Fishman, Tomer Maimon, Tali Perry, Patrick Venture,
Nancy Yuen, Benjamin Fair, Philipp Zabel, openbmc
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Function syscon_regmap_lookup_by_compat can return a NULL pointer, so
the IS_ERR check on the return is incorrect. Fix this by checking for
IS_ERR_OR_NULL and return -ENODEV if true. This avoids a null pointer
dereference on gcr_regmap later on.
Addresses-Coverity: ("Dereference null return (stat)")
Fixes: b3f1d036f26d ("reset: npcm: add NPCM reset controller driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/reset/reset-npcm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/reset/reset-npcm.c b/drivers/reset/reset-npcm.c
index 2ea4d3136e15..9febf8bed2f6 100644
--- a/drivers/reset/reset-npcm.c
+++ b/drivers/reset/reset-npcm.c
@@ -161,9 +161,9 @@ static int npcm_usb_reset(struct platform_device *pdev, struct npcm_rc_data *rc)
of_match_device(dev->driver->of_match_table, dev)->data;
gcr_regmap = syscon_regmap_lookup_by_compatible(gcr_dt);
- if (IS_ERR(gcr_regmap)) {
+ if (IS_ERR_OR_NULL(gcr_regmap)) {
dev_err(&pdev->dev, "Failed to find %s\n", gcr_dt);
- return PTR_ERR(gcr_regmap);
+ return -ENODEV;
}
/* checking which USB device is enabled */
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] reset: npcm: check for NULL return from syscon_regmap_lookup_by_compat
2019-11-08 15:55 [PATCH][next] reset: npcm: check for NULL return from syscon_regmap_lookup_by_compat Colin King
@ 2019-11-14 13:22 ` Philipp Zabel
2019-11-14 13:36 ` Colin Ian King
0 siblings, 1 reply; 3+ messages in thread
From: Philipp Zabel @ 2019-11-14 13:22 UTC (permalink / raw)
To: Colin King, Avi Fishman, Tomer Maimon, Tali Perry,
Patrick Venture, Nancy Yuen, Benjamin Fair, openbmc
Cc: kernel-janitors, linux-kernel
Hi Colin,
On Fri, 2019-11-08 at 15:55 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Function syscon_regmap_lookup_by_compat can return a NULL pointer, so
Could you point out where that NULL pointer would come from? As far as I
understand, syscon_regmap_lookup_by_compatible() should either return a
negative error code, or syscon->regmap, which should never be NULL.
> the IS_ERR check on the return is incorrect. Fix this by checking for
> IS_ERR_OR_NULL and return -ENODEV if true. This avoids a null pointer
> dereference on gcr_regmap later on.
>
> Addresses-Coverity: ("Dereference null return (stat)")
> Fixes: b3f1d036f26d ("reset: npcm: add NPCM reset controller driver")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/reset/reset-npcm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/reset/reset-npcm.c b/drivers/reset/reset-npcm.c
> index 2ea4d3136e15..9febf8bed2f6 100644
> --- a/drivers/reset/reset-npcm.c
> +++ b/drivers/reset/reset-npcm.c
> @@ -161,9 +161,9 @@ static int npcm_usb_reset(struct platform_device *pdev, struct npcm_rc_data *rc)
> of_match_device(dev->driver->of_match_table, dev)->data;
>
> gcr_regmap = syscon_regmap_lookup_by_compatible(gcr_dt);
> - if (IS_ERR(gcr_regmap)) {
> + if (IS_ERR_OR_NULL(gcr_regmap)) {
> dev_err(&pdev->dev, "Failed to find %s\n", gcr_dt);
> - return PTR_ERR(gcr_regmap);
> + return -ENODEV;
> }
>
> /* checking which USB device is enabled */
regards
Philipp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] reset: npcm: check for NULL return from syscon_regmap_lookup_by_compat
2019-11-14 13:22 ` Philipp Zabel
@ 2019-11-14 13:36 ` Colin Ian King
0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2019-11-14 13:36 UTC (permalink / raw)
To: Philipp Zabel, Avi Fishman, Tomer Maimon, Tali Perry,
Patrick Venture, Nancy Yuen, Benjamin Fair, openbmc
Cc: kernel-janitors, linux-kernel
On 14/11/2019 13:22, Philipp Zabel wrote:
> Hi Colin,
>
> On Fri, 2019-11-08 at 15:55 +0000, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Function syscon_regmap_lookup_by_compat can return a NULL pointer, so
>
> Could you point out where that NULL pointer would come from? As far as I
> understand, syscon_regmap_lookup_by_compatible() should either return a
> negative error code, or syscon->regmap, which should never be NULL.
Maybe I was over-zealous here with the results from the static analyzer.
Re-reading the call chain it does seem like I was mistaken. So NAK this
patch.
Apologies for the noise.
>
>> the IS_ERR check on the return is incorrect. Fix this by checking for
>> IS_ERR_OR_NULL and return -ENODEV if true. This avoids a null pointer
>> dereference on gcr_regmap later on.
>>
>> Addresses-Coverity: ("Dereference null return (stat)")
>> Fixes: b3f1d036f26d ("reset: npcm: add NPCM reset controller driver")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>> drivers/reset/reset-npcm.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/reset/reset-npcm.c b/drivers/reset/reset-npcm.c
>> index 2ea4d3136e15..9febf8bed2f6 100644
>> --- a/drivers/reset/reset-npcm.c
>> +++ b/drivers/reset/reset-npcm.c
>> @@ -161,9 +161,9 @@ static int npcm_usb_reset(struct platform_device *pdev, struct npcm_rc_data *rc)
>> of_match_device(dev->driver->of_match_table, dev)->data;
>>
>> gcr_regmap = syscon_regmap_lookup_by_compatible(gcr_dt);
>> - if (IS_ERR(gcr_regmap)) {
>> + if (IS_ERR_OR_NULL(gcr_regmap)) {
>> dev_err(&pdev->dev, "Failed to find %s\n", gcr_dt);
>> - return PTR_ERR(gcr_regmap);
>> + return -ENODEV;
>> }
>>
>> /* checking which USB device is enabled */
>
> regards
> Philipp
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-14 13:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 15:55 [PATCH][next] reset: npcm: check for NULL return from syscon_regmap_lookup_by_compat Colin King
2019-11-14 13:22 ` Philipp Zabel
2019-11-14 13:36 ` Colin Ian King
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).