Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp790297imu; Tue, 27 Nov 2018 06:22:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/VUrYQXG9Mm49I/WZlVWDhi8DugZHcT5TKp1893UjA+KEgenmne8fyoUp8GVCKlKQSlqpcY X-Received: by 2002:a62:6303:: with SMTP id x3mr89779pfb.110.1543328569952; Tue, 27 Nov 2018 06:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543328569; cv=none; d=google.com; s=arc-20160816; b=O1am1as/WeUcsxJMx7g9enRDVckByIsrb3mG92hFWpKdYrolouLygR+raX1MaElvvy uQd8PNlIsqUq5uJylQiU9S3LoH0MIC7qtH6IDgquHMlTB1sxu6bhG97g+0IeRjVZPKGa KEztoLCBO/Qta7BbV1U3HaSHMO7Nkj3Vywlx9i5yMZWo4tW6EuK4ITNX4LO+wDuWBY22 5AQEOmZp39QUcJKNO9H/uUS6UUjuMa7sQ0IGEsyQML6qKG0Lz6Ro7msn2aZjNkoi0Wnq 5Esb3GdG+Vj3ykPBq801UJOvOGXzLqNfH+qGtH/xW/A3+gxE88FwOIcLzyfRI+7N98/1 j34g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dkim-signature; bh=xehEJo/ZC+98SrynuSeKyeFfz+YHVz+9L7jEr3Ob4OY=; b=xKr2wuRirUxpyhnGp8n9tRmBpUNS08mcrDhSbYyapafbLjyvPASqwBeogXZ8m+ikue a+fhRbQ8ug5b5WlhDqTXSi7MqMQcBj8CzLsXEJD5knOdzUJDxvwIBDgEl04w3qdIsLlU whW0z+5dKbFHpBQdcSjBSTeBCs1yGGNePrBfYW9sFlOpFexr/00bG11t+q13DracqVZl VDpZNHDuLHie8IkV0qE+9PbXda2XOMImzD2yDcNmCDdVzd4ly1Lh1QgQfqZp/+K/b7hj qyswFi3svvc4tq+m1hsXuEkwCm9S9BNyan48WNRFRxmPBXWN2K2rC2LVlve9CUjTdqXH KGrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SB1noKHy; 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 q1-v6si3986568plb.14.2018.11.27.06.22.08; Tue, 27 Nov 2018 06:22:49 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SB1noKHy; 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 S1727416AbeK1Aeu (ORCPT + 99 others); Tue, 27 Nov 2018 19:34:50 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:46237 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbeK1Aet (ORCPT ); Tue, 27 Nov 2018 19:34:49 -0500 Received: by mail-ot1-f65.google.com with SMTP id w25so20056922otm.13 for ; Tue, 27 Nov 2018 05:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:reply-to:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=xehEJo/ZC+98SrynuSeKyeFfz+YHVz+9L7jEr3Ob4OY=; b=SB1noKHyA4vx/Z24BBQqEFlJgUi1FVc4PahnKaT6rKDf4cu9PsnO3GVbMNBu8HvBr3 WVVsnDBBsl49ZVw8SC3HkCLtrWhDbknhJz6qMZYyU4JOvfb5RdIEy8/iH1altoJZo62T B/bKdxS2xmpg6VOJxwBcLv1Jb4JMYDPysf6lUmNAX+o5xqaf+LJ0mbu7wnim4LJMB66l zlJ/6SVXf5a0GvlBmKYGlZIxgFvlUFF30OkgBMrD+AFSrOU6eQhBXZhjZRCEDAfM6xPX 0ngM8JiNj9s4Hx6p3YUimWx8n97RBoBB/YzlsjjdrfsAUlz+ZPlJvg28laECR6jbivQ8 sajg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=xehEJo/ZC+98SrynuSeKyeFfz+YHVz+9L7jEr3Ob4OY=; b=q4NQJ/1EMTWmbf4rvTLw7Ar7UTju6ZyUh1K55V6/57Gftlr0Mqm3nNehRjuoEyosbn LIJH3dsYHOZeN8wjfoOpGu9fxgObRjF+sJY9ua+W0rC8UYMfLgceBfqkybkNj6olU3kM GRakqTvKfMEW7hN07WwcZZoAaLiUmwqqUsgWpGOF4bkvTOWpuJof17Kmn01ttsuzqyM/ BUSjYbARhS5ECjTO+SSzWVQNYjW3MhZ5OMB08zsGM5X7NqxeQ3WrE61lxa7lhtdu/eL+ /6DAid8M6CsCafhoWG/9BarTVoIYbeRfTE4/M5+FTRuClrWFRYuFQOxe06BS4J4qJidm /xYw== X-Gm-Message-State: AA+aEWYPJizom7fXcv37Cxa7ldbm6I98XCIn2tF/3Ue20eSTL21wUzUY VOmzjt8N3Psf6nmu+a+NfA== X-Received: by 2002:a05:6830:2010:: with SMTP id e16mr16946767otp.86.1543325811187; Tue, 27 Nov 2018 05:36:51 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id z9sm2130903oiz.21.2018.11.27.05.36.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 05:36:50 -0800 (PST) Received: from [192.168.27.3] (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPSA id E2526915; Tue, 27 Nov 2018 07:36:48 -0600 (CST) Reply-To: minyard@acm.org Subject: Re: [PATCH] ipmi: kcs_bmc: handle devm_kasprintf() failure case To: Nicholas Mc Guire , Haiyue Wang Cc: Arnd Bergmann , Greg Kroah-Hartman , openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <1542812905-27337-1-git-send-email-hofrat@osadl.org> From: Corey Minyard Message-ID: <9320680f-679e-fc89-4349-17dbbd30bbfc@acm.org> Date: Tue, 27 Nov 2018 07:36:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1542812905-27337-1-git-send-email-hofrat@osadl.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > 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;