* [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference @ 2014-05-17 17:14 Rickard Strandqvist [not found] ` <1400346848-25098-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Rickard Strandqvist @ 2014-05-17 17:14 UTC (permalink / raw) To: Wolfram Sang, Grant Likely Cc: Rickard Strandqvist, Rob Herring, Jingoo Han, Leilei Shang, Daniel Drake, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA There is otherwise a risk of a possible null pointer dereference. Was largely found by using a static code analysis program called cppcheck. Signed-off-by: Rickard Strandqvist <rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> --- drivers/i2c/busses/i2c-pxa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index bbe6dfb..dbe5ebe 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1269,7 +1269,9 @@ eremap: eclk: kfree(i2c); emalloc: - release_mem_region(res->start, resource_size(res)); + if(res) { + release_mem_region(res->start, resource_size(res)); + } return ret; } -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
[parent not found: <1400346848-25098-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org>]
* Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference [not found] ` <1400346848-25098-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> @ 2014-05-17 17:18 ` Mateusz Guzik 2014-06-01 20:26 ` Wolfram Sang 1 sibling, 0 replies; 5+ messages in thread From: Mateusz Guzik @ 2014-05-17 17:18 UTC (permalink / raw) To: Rickard Strandqvist Cc: Wolfram Sang, Grant Likely, Rob Herring, Jingoo Han, Leilei Shang, Daniel Drake, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA On Sat, May 17, 2014 at 07:14:08PM +0200, Rickard Strandqvist wrote: > There is otherwise a risk of a possible null pointer dereference. > > Was largely found by using a static code analysis program called cppcheck. > > Signed-off-by: Rickard Strandqvist <rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> > --- > drivers/i2c/busses/i2c-pxa.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > index bbe6dfb..dbe5ebe 100644 > --- a/drivers/i2c/busses/i2c-pxa.c > +++ b/drivers/i2c/busses/i2c-pxa.c > @@ -1269,7 +1269,9 @@ eremap: > eclk: > kfree(i2c); > emalloc: > - release_mem_region(res->start, resource_size(res)); > + if(res) { > + release_mem_region(res->start, resource_size(res)); > + } > return ret; > } > This looks incorrect. request_mem_region, which I believe is a prerequisite for this function may not be called when you jump here. -- Mateusz Guzik ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference [not found] ` <1400346848-25098-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> 2014-05-17 17:18 ` Mateusz Guzik @ 2014-06-01 20:26 ` Wolfram Sang 2014-06-02 1:55 ` Jingoo Han 1 sibling, 1 reply; 5+ messages in thread From: Wolfram Sang @ 2014-06-01 20:26 UTC (permalink / raw) To: Rickard Strandqvist Cc: Grant Likely, Rob Herring, Jingoo Han, Leilei Shang, Daniel Drake, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 994 bytes --] On Sat, May 17, 2014 at 07:14:08PM +0200, Rickard Strandqvist wrote: > There is otherwise a risk of a possible null pointer dereference. > > Was largely found by using a static code analysis program called cppcheck. It is useful to put the output of the analyzer here. > > Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> > --- > drivers/i2c/busses/i2c-pxa.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > index bbe6dfb..dbe5ebe 100644 > --- a/drivers/i2c/busses/i2c-pxa.c > +++ b/drivers/i2c/busses/i2c-pxa.c > @@ -1269,7 +1269,9 @@ eremap: > eclk: > kfree(i2c); > emalloc: > - release_mem_region(res->start, resource_size(res)); > + if(res) { > + release_mem_region(res->start, resource_size(res)); > + } The proper fix is to move the release to the proper place, before kfree. Even better would probably be a devm_* conversion. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference 2014-06-01 20:26 ` Wolfram Sang @ 2014-06-02 1:55 ` Jingoo Han 2014-06-02 10:15 ` Rickard Strandqvist 0 siblings, 1 reply; 5+ messages in thread From: Jingoo Han @ 2014-06-02 1:55 UTC (permalink / raw) To: 'Rickard Strandqvist', 'Wolfram Sang' Cc: 'Grant Likely', 'Rob Herring', 'Leilei Shang', 'Daniel Drake', linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, 'Jingoo Han' On Monday, June 02, 2014 5:27 AM, Wolfram Sang wrote: > On Sat, May 17, 2014 at 07:14:08PM +0200, Rickard Strandqvist wrote: > > There is otherwise a risk of a possible null pointer dereference. > > > > Was largely found by using a static code analysis program called cppcheck. > > It is useful to put the output of the analyzer here. > > > > > Signed-off-by: Rickard Strandqvist <rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> > > --- > > drivers/i2c/busses/i2c-pxa.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > > index bbe6dfb..dbe5ebe 100644 > > --- a/drivers/i2c/busses/i2c-pxa.c > > +++ b/drivers/i2c/busses/i2c-pxa.c > > @@ -1269,7 +1269,9 @@ eremap: > > eclk: > > kfree(i2c); > > emalloc: > > - release_mem_region(res->start, resource_size(res)); > > + if(res) { > > + release_mem_region(res->start, resource_size(res)); > > + } > > The proper fix is to move the release to the proper place, before kfree. > Even better would probably be a devm_* conversion. +1 I agree with Wolfram Sang's opinion. Please call release_mem_region() prior to kfree(). One more thing, don't use braces when a single statement is used. Please refer to 'Chapter 3: Placing Braces and Spaces' of 'Documentation/CodingStyle'. Best regards, Jingoo Han -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference 2014-06-02 1:55 ` Jingoo Han @ 2014-06-02 10:15 ` Rickard Strandqvist 0 siblings, 0 replies; 5+ messages in thread From: Rickard Strandqvist @ 2014-06-02 10:15 UTC (permalink / raw) To: Jingoo Han Cc: Leilei Shang, Rob Herring, linux-i2c, Wolfram Sang, devicetree, Grant Likely, linux-kernel, Daniel Drake [-- Attachment #1: Type: text/plain, Size: 1405 bytes --] Hi Ok, working on it. New patch later then.. On Monday, June 02, 2014 5:27 AM, Wolfram Sang wrote: > On Sat, May 17, 2014 at 07:14:08PM +0200, Rickard Strandqvist wrote: > > There is otherwise a risk of a possible null pointer dereference. > > > > Was largely found by using a static code analysis program called cppcheck. > > It is useful to put the output of the analyzer here. > > > > > Signed-off-by: Rickard Strandqvist < rickard_strandqvist@spectrumdigital.se> > > --- > > drivers/i2c/busses/i2c-pxa.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > > index bbe6dfb..dbe5ebe 100644 > > --- a/drivers/i2c/busses/i2c-pxa.c > > +++ b/drivers/i2c/busses/i2c-pxa.c > > @@ -1269,7 +1269,9 @@ eremap: > > eclk: > > kfree(i2c); > > emalloc: > > - release_mem_region(res->start, resource_size(res)); > > + if(res) { > > + release_mem_region(res->start, resource_size(res)); > > + } > > The proper fix is to move the release to the proper place, before kfree. > Even better would probably be a devm_* conversion. +1 I agree with Wolfram Sang's opinion. Please call release_mem_region() prior to kfree(). One more thing, don't use braces when a single statement is used. Please refer to 'Chapter 3: Placing Braces and Spaces' of 'Documentation/CodingStyle'. Best regards, Jingoo Han [-- Attachment #2: Type: text/html, Size: 2032 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-02 10:15 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-05-17 17:14 [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference Rickard Strandqvist [not found] ` <1400346848-25098-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org> 2014-05-17 17:18 ` Mateusz Guzik 2014-06-01 20:26 ` Wolfram Sang 2014-06-02 1:55 ` Jingoo Han 2014-06-02 10:15 ` Rickard Strandqvist
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).