public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Staging: wilc1000: Remove null check before kfree
@ 2015-08-10  8:00 Shraddha Barke
  2015-08-10  8:00 ` [PATCH 2/3] Staging: lustre: libcfs: Remove unnecessary cast on void* Shraddha Barke
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shraddha Barke @ 2015-08-10  8:00 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Benjamin Romer,
	Johnny Kim, Rachel Kim, HPDD-discuss, linux-kernel,
	linux-wireless
  Cc: Shraddha Barke

kfree on NULL pointer is a no-op.

This patch uses the following semantic patch to find such an instance
where NULL check is present before kfree.

// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
 drivers/staging/wilc1000/linux_wlan.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 3e55a8a..3dcd6e5 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -2343,8 +2343,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 
 done:
 
-	if (buff != NULL)
-		kfree(buff);
+	kfree(buff);
 
 	return s32Error;
 }
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] Staging: lustre: libcfs: Remove unnecessary cast on void*
  2015-08-10  8:00 [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Shraddha Barke
@ 2015-08-10  8:00 ` Shraddha Barke
  2015-08-10  8:00 ` [PATCH 3/3] Staging: unisys: Remove useless cast on void pointer Shraddha Barke
  2015-08-10 23:30 ` [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Dilger, Andreas
  2 siblings, 0 replies; 4+ messages in thread
From: Shraddha Barke @ 2015-08-10  8:00 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Benjamin Romer,
	Johnny Kim, Rachel Kim, HPDD-discuss, linux-kernel,
	linux-wireless
  Cc: Shraddha Barke

This patch does away with the cast on void * as it is unnecessary.

Semantic patch used is as follows:

@r@
expression x;
void* e;
type T;
identifier f;
@@
(
  *((T *)e)
|
  ((T *)x)[...]
|
  ((T *)x)->f
|
- (void *)
  e
)

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
 drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
index 1ab4232..ef8f126 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -335,7 +335,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *a
 		return -ENOMEM;
 
 	/* 'cmd' and permissions get checked in our arch-specific caller */
-	if (libcfs_ioctl_getdata(buf, buf + 800, (void *)arg)) {
+	if (libcfs_ioctl_getdata(buf, buf + 800, arg)) {
 		CERROR("PORTALS ioctl: data error\n");
 		err = -EINVAL;
 		goto out;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] Staging: unisys: Remove useless cast on void pointer
  2015-08-10  8:00 [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Shraddha Barke
  2015-08-10  8:00 ` [PATCH 2/3] Staging: lustre: libcfs: Remove unnecessary cast on void* Shraddha Barke
@ 2015-08-10  8:00 ` Shraddha Barke
  2015-08-10 23:30 ` [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Dilger, Andreas
  2 siblings, 0 replies; 4+ messages in thread
From: Shraddha Barke @ 2015-08-10  8:00 UTC (permalink / raw)
  To: Oleg Drokin, Andreas Dilger, Greg Kroah-Hartman, Benjamin Romer,
	Johnny Kim, Rachel Kim, HPDD-discuss, linux-kernel,
	linux-wireless
  Cc: Shraddha Barke

void pointers do not need to be cast to other pointer types.

The semantic patch used to find this:

@r@
expression x;
void* e;
type T;
identifier f;
@@
(
  *((T *)e)
|
  ((T *)x)[...]
|
  ((T *)x)->f
|
- (T *)
  e
)

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
 drivers/staging/unisys/visorbus/visorbus_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 403c13b..db4282f 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -677,7 +677,7 @@ unregister_driver_attributes(struct visor_driver *drv)
 static void
 dev_periodic_work(void *xdev)
 {
-	struct visor_device *dev = (struct visor_device *)xdev;
+	struct visor_device *dev = xdev;
 	struct visor_driver *drv = to_visor_driver(dev->device.driver);
 
 	down(&dev->visordriver_callback_lock);
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] Staging: wilc1000: Remove null check before kfree
  2015-08-10  8:00 [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Shraddha Barke
  2015-08-10  8:00 ` [PATCH 2/3] Staging: lustre: libcfs: Remove unnecessary cast on void* Shraddha Barke
  2015-08-10  8:00 ` [PATCH 3/3] Staging: unisys: Remove useless cast on void pointer Shraddha Barke
@ 2015-08-10 23:30 ` Dilger, Andreas
  2 siblings, 0 replies; 4+ messages in thread
From: Dilger, Andreas @ 2015-08-10 23:30 UTC (permalink / raw)
  To: Shraddha Barke, Drokin, Oleg, Greg Kroah-Hartman, Benjamin Romer,
	Johnny Kim, Rachel Kim, linux-kernel@vger.kernel.org

On 2015/08/10, 2:00 AM, "Shraddha Barke" <shraddha.6596@gmail.com> wrote:

>kfree on NULL pointer is a no-op.

Hi, please don't CC the hpdd-discuss list, nor Oleg or I for patches
unrelated to Lustre.

Cheers, Andreas

>This patch uses the following semantic patch to find such an instance
>where NULL check is present before kfree.
>
>// <smpl>
>@@ expression E; @@
>- if (E != NULL) { kfree(E); }
>+ kfree(E);
>@@ expression E; @@
>- if (E != NULL) { kfree(E); E = NULL; }
>+ kfree(E);
>+ E = NULL;
>// </smpl>smpl>
>
>Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
>---
> drivers/staging/wilc1000/linux_wlan.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/drivers/staging/wilc1000/linux_wlan.c
>b/drivers/staging/wilc1000/linux_wlan.c
>index 3e55a8a..3dcd6e5 100644
>--- a/drivers/staging/wilc1000/linux_wlan.c
>+++ b/drivers/staging/wilc1000/linux_wlan.c
>@@ -2343,8 +2343,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq
>*req, int cmd)
> 
> done:
> 
>-	if (buff != NULL)
>-		kfree(buff);
>+	kfree(buff);
> 
> 	return s32Error;
> }
>-- 
>2.1.0
>
>


Cheers, Andreas
-- 
Andreas Dilger

Lustre Software Architect
Intel High Performance Data Division



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-08-10 23:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-10  8:00 [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Shraddha Barke
2015-08-10  8:00 ` [PATCH 2/3] Staging: lustre: libcfs: Remove unnecessary cast on void* Shraddha Barke
2015-08-10  8:00 ` [PATCH 3/3] Staging: unisys: Remove useless cast on void pointer Shraddha Barke
2015-08-10 23:30 ` [PATCH 1/3] Staging: wilc1000: Remove null check before kfree Dilger, Andreas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox