diff mbox

ASoC: Intel: fix ifnullfree.cocci warnings

Message ID 20150412190626.GA28170@athens.lkp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fengguang Wu April 12, 2015, 7:06 p.m. UTC
sound/soc/intel/common/sst-ipc.c:287:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values.

 NULL check before some freeing functions is not needed.

 Based on checkpatch warning
 "kfree(NULL) is safe this check is probably not required"
 and kfreeaddr.cocci by Julia Lawall.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

CC: Jin Yao <yao.jin@linux.intel.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 sst-ipc.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Jin, Yao April 13, 2015, 1:03 a.m. UTC | #1
The NULL check here is to proivde the protection for current code and
future potential code. It's possible that in future some code may
change the pointer ipc->msg and the author may miss the kfree here.

But anyway I'm ok if removing null check is the coding philosophy we
need to follow.

Thanks
JIn Yao

On 2015/4/13 3:06, kbuild test robot wrote:
> sound/soc/intel/common/sst-ipc.c:287:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values.
> 
>  NULL check before some freeing functions is not needed.
> 
>  Based on checkpatch warning
>  "kfree(NULL) is safe this check is probably not required"
>  and kfreeaddr.cocci by Julia Lawall.
> 
> Generated by: scripts/coccinelle/free/ifnullfree.cocci
> 
> CC: Jin Yao <yao.jin@linux.intel.com>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
> ---
> 
>  sst-ipc.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> --- a/sound/soc/intel/common/sst-ipc.c
> +++ b/sound/soc/intel/common/sst-ipc.c
> @@ -283,8 +283,7 @@ void sst_ipc_fini(struct sst_generic_ipc
>  	if (ipc->tx_thread)
>  		kthread_stop(ipc->tx_thread);
>  
> -	if (ipc->msg)
> -		kfree(ipc->msg);
> +	kfree(ipc->msg);
>  }
>  EXPORT_SYMBOL_GPL(sst_ipc_fini);
>  
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
Mark Brown April 13, 2015, 10:38 a.m. UTC | #2
On Mon, Apr 13, 2015 at 09:03:39AM +0800, Jin, Yao wrote:
> The NULL check here is to proivde the protection for current code and
> future potential code. It's possible that in future some code may
> change the pointer ipc->msg and the author may miss the kfree here.

That's not the point - the point is that if it's ever valid to call
kfree() then passing a null pointer in is fine.
diff mbox

Patch

--- a/sound/soc/intel/common/sst-ipc.c
+++ b/sound/soc/intel/common/sst-ipc.c
@@ -283,8 +283,7 @@  void sst_ipc_fini(struct sst_generic_ipc
 	if (ipc->tx_thread)
 		kthread_stop(ipc->tx_thread);
 
-	if (ipc->msg)
-		kfree(ipc->msg);
+	kfree(ipc->msg);
 }
 EXPORT_SYMBOL_GPL(sst_ipc_fini);