Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2139546imu; Wed, 21 Nov 2018 07:15:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/V4c7FnpcNOk+Sl6HaN7pEVbrX0Fq1vIoh3dnQqKfOzob+mQ0E/5Oe+X17fCEmgo3h96Jig X-Received: by 2002:a63:d005:: with SMTP id z5mr6329799pgf.64.1542813317808; Wed, 21 Nov 2018 07:15:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542813317; cv=none; d=google.com; s=arc-20160816; b=iMrosV/WojQR64Md1SbVHV+4IcNkHmz/WnbOtu2OCOh86+xF/zktsoWpJ+wEm9IsJw OX52LZu9qqIaHyoD1zhi4ub3O60X5SVeYHDGN71NTv3KLHMkRwdq0MM7RkwPlp/h1bou iQ+KAxbboo2wXar64aoQ/MiM3FbtqliAyHiqFRyXPPm050NfZrdB8NdK7u3GZtciiSpR nH0WXSC+QpwPxhgqIIYnfmo4OxcYgXK0YxcyPOuoRSLJ76Cib11yxyoXnBmV9fLwoupr xDL8EEjrb/LRv5hKEDYlWmNe/uH7Z8RpcBWGyv/J9K/EsxVCC0ZIM3ZuxyST7hnA/FpY AwBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=jRE0ZY+YiK0jNqey/txZjPY4Z619UhPX0Aj6Js6zRrQ=; b=C3Yqw67MSd3ZquJW9dVU+qWn+dQuKD9uoOXXZ+5T0+RJKdnggnXNmqWKCoG4uzHfwH u7YcVmXKCjKtlMFhZ8neW7pY4YQAoocibTnH59aI8zfEkMiJxTOaNV7F+cfX6F/vbOJ6 cxJ/JfYjhhjkNxgYiFDSMxjJDtYNodKyVjl+GYSiHlokpALAO4wsQfXQmlXmIWMPFwau 9BjefkVpSwE42DzVhMiGGk8pJ59lG8RJTBSqaCBMJ2luQ+GMhVgE6GQ4erM1qkB180Fy z5dREuv+y74kAPtxVHUIqo8Wl1FfKz5N2Ar8jO7IHutdQMyUfFUME4kedQAeD2wmPb6W oDZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4-v6si48008453pla.203.2018.11.21.07.14.51; Wed, 21 Nov 2018 07:15:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731120AbeKVBrq (ORCPT + 99 others); Wed, 21 Nov 2018 20:47:46 -0500 Received: from www.osadl.org ([62.245.132.105]:40127 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726849AbeKVBrq (ORCPT ); Wed, 21 Nov 2018 20:47:46 -0500 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wALFBPGA000596; Wed, 21 Nov 2018 16:11:25 +0100 From: Nicholas Mc Guire To: Corey Minyard Cc: Arnd Bergmann , Greg Kroah-Hartman , openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case Date: Wed, 21 Nov 2018 16:08:25 +0100 Message-Id: <1542812905-27337-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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