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: 107863 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3386048qge; Sun, 16 Jul 2017 06:35:00 -0700 (PDT) X-Received: by 10.84.224.15 with SMTP id r15mr25077555plj.78.1500212100912; Sun, 16 Jul 2017 06:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500212100; cv=none; d=google.com; s=arc-20160816; b=D/rPbC1OG8jEEN+Edp2746O1mdu9/3KIaz7ZeEvXgYq11CGP+PFCt9bq81e0ZFu27l 0vgMQ7udu9zDa52MD2BV2s1TaivP14eNKCu1n+txBeH0v7k65b7JT1iUmpfPPinzU84Q Lgk7NxnMYSVT4YqAca0AM+mZnnmEU/3BZklOTNZIuo4aTEA5Gen1HklJ85XZKxE5lidK bT0Gn+56A6dGn7NmuNDBgtefAif5v9r6t+UbWlcJRsM5RyRqQe5GZIJ3VAc0X8qWAWhs ZxyAF3r4Z1d9R5t1ceVQIPjvMrI7dzF5oUZyC2ZbNjHHJ9gK0h0lgNNXr+dFescCEvD/ plPw== 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 :dmarc-filter:arc-authentication-results; bh=Qo46sTjfhvCi8ta/zsgn0T5NcTFjqQQN9D0rp2rwyEY=; b=djR/Yj5G+b6XvynH8FHix9MDyl2Bx/0H7YE25YKIV2pbkSCkodnyTskxmG5Eon120a rgRCQi4z1dTfl9v9wzCzvaME46T9PFgOib3B+6r3T1uBle/i9kEIImT6XKFLuLy6eAIx 2Yb90xAuHdMpT6gTOoTPxIoTZEyF7EWrR9ofnRRqBOJCOu1aRF3/9dC9vreKoVMVsTvA fSkqL/Ur0Jg7oPis0eSaS0DKee2BGUnC4xERNxXiWo/s8HGnBBvSAyepivXDlxYB9JMM khyezqWjr7MqeBmzvri26P0t6mPsnrhgdjehWBvGFdFINlVoNAy4o8i5OjS889Y4wTsK evAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-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 m17si6277616pge.71.2017.07.16.06.35.00; Sun, 16 Jul 2017 06:35:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbdGPNfA (ORCPT + 4 others); Sun, 16 Jul 2017 09:35:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:54980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbdGPNe7 (ORCPT ); Sun, 16 Jul 2017 09:34:59 -0400 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 Cc: Dan Carpenter , Baoyou Xie , Xin Zhou , Jun Nie , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Shawn Guo 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 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;