Skip to content

Commit

Permalink
ipmi: kcs_bmc: handle devm_kasprintf() failure case
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: cd2315d ("ipmi: kcs_bmc: don't change device name")
Signed-off-by: Corey Minyard <[email protected]>
Reviewed-by: Haiyue Wang <[email protected]>
  • Loading branch information
Nicholas Mc Guire authored and cminyard committed Feb 10, 2019
1 parent 95ac0da commit 42c7c6e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/char/ipmi/kcs_bmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 42c7c6e

Please sign in to comment.