linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case
@ 2018-11-21 15:08 Nicholas Mc Guire
  2018-11-27 13:36 ` Corey Minyard
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Mc Guire @ 2018-11-21 15:08 UTC (permalink / raw)
  To: Corey Minyard
  Cc: Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer,
	linux-kernel, Nicholas Mc Guire

devm_kasprintf() may return NULL if internal allocation failed so this
assignment is not safe. Moved the error exit path and added the !NULL
which then allows the devres manager to take care of cleanup.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes: cd2315d471f4 ("ipmi: kcs_bmc: don't change device name")
---

Problem located with experimental coccinelle script

Patch was compile tested with: aspeed_g5_defconfig (implies
CONFIG_IPMI_KCS_BMC=y)

Patch is against 4.20-rc3 (localversion-next is next-20181121)

 drivers/char/ipmi/kcs_bmc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index e6124bd..86d29d2 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -440,12 +440,13 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
 	kcs_bmc->data_in = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
 	kcs_bmc->data_out = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
 	kcs_bmc->kbuffer = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
-	if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer)
-		return NULL;
 
 	kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
 	kcs_bmc->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s%u",
 					       DEVICE_NAME, channel);
+	if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer ||
+	    !kcs_bmc->miscdev.name)
+		return NULL;
 	kcs_bmc->miscdev.fops = &kcs_bmc_fops;
 
 	return kcs_bmc;
-- 
2.1.4


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

* Re: [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case
  2018-11-21 15:08 [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case Nicholas Mc Guire
@ 2018-11-27 13:36 ` Corey Minyard
  2018-11-28  0:54   ` Wang, Haiyue
  0 siblings, 1 reply; 4+ messages in thread
From: Corey Minyard @ 2018-11-27 13:36 UTC (permalink / raw)
  To: Nicholas Mc Guire, Haiyue Wang
  Cc: Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer, linux-kernel

On 11/21/18 9:08 AM, Nicholas Mc Guire wrote:
> devm_kasprintf() may return NULL if internal allocation failed so this
> assignment is not safe. Moved the error exit path and added the !NULL
> which then allows the devres manager to take care of cleanup.


Added the original author.  This looks correct to me, I've included it, 
but I would
like Haiyue to comment, if possible.

Thanks,

-corey


> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Fixes: cd2315d471f4 ("ipmi: kcs_bmc: don't change device name")
> ---
>
> Problem located with experimental coccinelle script
>
> Patch was compile tested with: aspeed_g5_defconfig (implies
> CONFIG_IPMI_KCS_BMC=y)
>
> Patch is against 4.20-rc3 (localversion-next is next-20181121)
>
>   drivers/char/ipmi/kcs_bmc.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
> index e6124bd..86d29d2 100644
> --- a/drivers/char/ipmi/kcs_bmc.c
> +++ b/drivers/char/ipmi/kcs_bmc.c
> @@ -440,12 +440,13 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
>   	kcs_bmc->data_in = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
>   	kcs_bmc->data_out = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
>   	kcs_bmc->kbuffer = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL);
> -	if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer)
> -		return NULL;
>   
>   	kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR;
>   	kcs_bmc->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s%u",
>   					       DEVICE_NAME, channel);
> +	if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer ||
> +	    !kcs_bmc->miscdev.name)
> +		return NULL;
>   	kcs_bmc->miscdev.fops = &kcs_bmc_fops;
>   
>   	return kcs_bmc;



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

* Re: [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case
  2018-11-27 13:36 ` Corey Minyard
@ 2018-11-28  0:54   ` Wang, Haiyue
  2018-11-28  0:55     ` [Openipmi-developer] " Corey Minyard
  0 siblings, 1 reply; 4+ messages in thread
From: Wang, Haiyue @ 2018-11-28  0:54 UTC (permalink / raw)
  To: minyard, Nicholas Mc Guire
  Cc: Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer, linux-kernel

[Resend for wrong reply HTML format mail]

Great check for making kcs_bmc module be more stable and handle things gracefully.

My tag if needed.
      Reviewed-by: Haiyue Wang<haiyue.wang@linux.intel.com>

在 2018-11-27 21:36, Corey Minyard 写道:
> On 11/21/18 9:08 AM, Nicholas Mc Guire wrote:
>> devm_kasprintf() may return NULL if internal allocation failed so this
>> assignment is not safe. Moved the error exit path and added the !NULL
>> which then allows the devres manager to take care of cleanup.
>
>
> Added the original author.  This looks correct to me, I've included 
> it, but I would
> like Haiyue to comment, if possible.
>
> Thanks,
>
> -corey
>
>
>> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
>> Fixes: cd2315d471f4 ("ipmi: kcs_bmc: don't change device name") 

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

* Re: [Openipmi-developer] [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case
  2018-11-28  0:54   ` Wang, Haiyue
@ 2018-11-28  0:55     ` Corey Minyard
  0 siblings, 0 replies; 4+ messages in thread
From: Corey Minyard @ 2018-11-28  0:55 UTC (permalink / raw)
  To: Wang, Haiyue, Nicholas Mc Guire
  Cc: Greg Kroah-Hartman, openipmi-developer, linux-kernel, Arnd Bergmann

On 11/27/18 6:54 PM, Wang, Haiyue wrote:
> [Resend for wrong reply HTML format mail]
>
> Great check for making kcs_bmc module be more stable and handle things 
> gracefully.
>
> My tag if needed.
>      Reviewed-by: Haiyue Wang<haiyue.wang@linux.intel.com>
>
Thanks for the review, it's included.

-corey


> 在 2018-11-27 21:36, Corey Minyard 写道:
>> On 11/21/18 9:08 AM, Nicholas Mc Guire wrote:
>>> devm_kasprintf() may return NULL if internal allocation failed so this
>>> assignment is not safe. Moved the error exit path and added the !NULL
>>> which then allows the devres manager to take care of cleanup.
>>
>>
>> Added the original author.  This looks correct to me, I've included 
>> it, but I would
>> like Haiyue to comment, if possible.
>>
>> Thanks,
>>
>> -corey
>>
>>
>>> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
>>> Fixes: cd2315d471f4 ("ipmi: kcs_bmc: don't change device name") 
>
>
> _______________________________________________
> Openipmi-developer mailing list
> Openipmi-developer@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openipmi-developer



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

end of thread, other threads:[~2018-11-28  0:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-21 15:08 [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case Nicholas Mc Guire
2018-11-27 13:36 ` Corey Minyard
2018-11-28  0:54   ` Wang, Haiyue
2018-11-28  0:55     ` [Openipmi-developer] " Corey Minyard

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).