* [PATCH] staging: unisys: virtpci: virtpci.c: Fix for possible null pointer dereference
@ 2014-12-14 22:41 Rickard Strandqvist
2014-12-14 22:41 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Rickard Strandqvist @ 2014-12-14 22:41 UTC (permalink / raw)
To: Benjamin Romer, David Kershner
Cc: Rickard Strandqvist, Greg Kroah-Hartman, Ken Cox, Erik Arfvidson,
Silvio F, sparmaintainer, devel, linux-kernel
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@spectrumdigital.se>
---
drivers/staging/unisys/virtpci/virtpci.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index ee9f826..d818eda 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -1314,15 +1314,13 @@ static ssize_t virtpci_driver_attr_show(struct kobject *kobj,
ssize_t ret = 0;
struct driver_private *dprivate = to_driver(kobj);
- struct device_driver *driver;
- if (dprivate != NULL)
- driver = dprivate->driver;
- else
- driver = NULL;
+ if (dprivate) {
+ struct device_driver *driver = dprivate->driver;
+
+ DBGINF("In virtpci_driver_attr_show driver->name:%s\n",
+ driver->name);
- DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver->name);
- if (driver) {
if (dattr->show)
ret = dattr->show(driver, buf);
}
@@ -1337,16 +1335,13 @@ static ssize_t virtpci_driver_attr_store(struct kobject *kobj,
ssize_t ret = 0;
struct driver_private *dprivate = to_driver(kobj);
- struct device_driver *driver;
- if (dprivate != NULL)
- driver = dprivate->driver;
- else
- driver = NULL;
+ if (dprivate) {
+ struct device_driver *driver = dprivate->driver;
- DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver->name);
+ DBGINF("In virtpci_driver_attr_store driver->name:%s\n",
+ driver->name);
- if (driver) {
if (dattr->store)
ret = dattr->store(driver, buf, count);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: unisys: virtpci: virtpci.c: Fix for possible null pointer dereference
2014-12-14 22:41 [PATCH] staging: unisys: virtpci: virtpci.c: Fix for possible null pointer dereference Rickard Strandqvist
@ 2014-12-14 22:41 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2014-12-14 22:41 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Benjamin Romer, David Kershner, Ken Cox, Erik Arfvidson, Silvio F,
sparmaintainer, devel, linux-kernel
On Sun, Dec 14, 2014 at 11:41:11PM +0100, 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@spectrumdigital.se>
> ---
> drivers/staging/unisys/virtpci/virtpci.c | 23 +++++++++--------------
> 1 file changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
> index ee9f826..d818eda 100644
> --- a/drivers/staging/unisys/virtpci/virtpci.c
> +++ b/drivers/staging/unisys/virtpci/virtpci.c
> @@ -1314,15 +1314,13 @@ static ssize_t virtpci_driver_attr_show(struct kobject *kobj,
> ssize_t ret = 0;
>
> struct driver_private *dprivate = to_driver(kobj);
> - struct device_driver *driver;
>
> - if (dprivate != NULL)
> - driver = dprivate->driver;
> - else
> - driver = NULL;
> + if (dprivate) {
It is impossible for dprivate to ever be NULL, someone doesn't
understand how kobjects work :(
So just remove the check please, don't add more logic that will never
run.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-12-14 22:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-14 22:41 [PATCH] staging: unisys: virtpci: virtpci.c: Fix for possible null pointer dereference Rickard Strandqvist
2014-12-14 22:41 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox