From patchwork Sun Jul 16 13:33:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 9842953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2591B60212 for ; Sun, 16 Jul 2017 13:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140662846C for ; Sun, 16 Jul 2017 13:35:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E90D628470; Sun, 16 Jul 2017 13:35:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E1E472846C for ; Sun, 16 Jul 2017 13:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=g7zhoqzgVLtWmbPZcT3dyFGGmiGpjL3L37BGZFlCXZA=; b=pDH Cfj8DRQehmitYXvuSB+8oB6YFIr5uVQvoVnYlIdptjUYAykyXxhFTChteGONf3UAfxo2ecRihpDDP laDdc/ZqcW9BhVCpTZhhYvCk7ufiPPaCGMwROyVzXez91n9rF+bXcOLKXjWfoweb2PAoPuT94mxk8 xOCJ0RimW8zWvSswVDgTYmllFsACr9euZGFppa7iyiY+R8HnW8Hn58rMIz393RBrtfGMQmPF4PJSZ zyeVULcluTpJ09uoEeCYC/6+DolK1Hqt6aq4d20aycfUOYaPapXfcWdYqR5Z+GZuqH1xGSFodlmj1 xG/1O4wBC5uPpp2L5h2uh6QtBSqGbXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dWjho-0000Xw-Uj; Sun, 16 Jul 2017 13:35:29 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dWjhk-0007lF-Jr for linux-arm-kernel@lists.infradead.org; Sun, 16 Jul 2017 13:35:26 +0000 Received: from localhost.localdomain (li411-102.members.linode.com [106.187.91.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2801D22C7D; Sun, 16 Jul 2017 13:34:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2801D22C7D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=shawnguo@kernel.org From: Shawn Guo To: Linus Walleij Subject: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() Date: Sun, 16 Jul 2017 21:33:28 +0800 Message-Id: <1500212008-29321-1-git-send-email-shawnguo@kernel.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170716_063524_719913_BE6DB420 X-CRM114-Status: GOOD ( 10.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shawn Guo , Baoyou Xie , linux-gpio@vger.kernel.org, Xin Zhou , Jun Nie , Dan Carpenter , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shawn Guo It fixes the following Smatch static check warning: drivers/pinctrl/zte/pinctrl-zx.c:338 zx_pinctrl_build_state() warn: passing devm_ allocated variable to kfree. As we will be calling krealloc() on pointer 'functions', which means kfree() will be called in there, devm_kzalloc() shouldn't be used with the allocation in the first place. Fix the warning by calling kcalloc() and managing the free procedure in error path on our own. Reported-by: Dan Carpenter Fixes: cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support") Signed-off-by: Shawn Guo --- drivers/pinctrl/zte/pinctrl-zx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/zte/pinctrl-zx.c b/drivers/pinctrl/zte/pinctrl-zx.c index f828ee340a98..ded366bb6564 100644 --- a/drivers/pinctrl/zte/pinctrl-zx.c +++ b/drivers/pinctrl/zte/pinctrl-zx.c @@ -295,8 +295,7 @@ static int zx_pinctrl_build_state(struct platform_device *pdev) pctldev->num_groups = ngroups; /* Build function list from pin mux functions */ - functions = devm_kzalloc(&pdev->dev, info->npins * sizeof(*functions), - GFP_KERNEL); + functions = kcalloc(info->npins, sizeof(*functions), GFP_KERNEL); if (!functions) return -ENOMEM; @@ -367,8 +366,10 @@ static int zx_pinctrl_build_state(struct platform_device *pdev) func->num_group_names * sizeof(*func->group_names), GFP_KERNEL); - if (!func->group_names) + if (!func->group_names) { + kfree(functions); return -ENOMEM; + } } group = func->group_names;