From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F46BC636D4 for ; Wed, 15 Feb 2023 13:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=JFQSMRyJO8Ha2yjR5oNoGj6VInegIN4FlSzt4yoaoCM=; b=uup+oFh3M9Cex3 eeCINMvvtZAXd2QwAeqWSDPWXxXSvlKn4q1yVLlvY8kQ9KY6l7QgzfkIraNBWHNpkvGT/meuMo71T 813X8km1xwTVAzXxXRPGzv4jWoPv7pX3VJhzVFO4Y/iRv1nSiV3Tecp5eaAPtYdFxBPXU5w9kfwbq cgRnQaH07K9L9SBv75o+fcT8kSK8kto+DqefCoMS/4xhjzwi/fNXkay7Ef994q3LTgE7zKAj75OhS 5SvD2CSeGhK8k8JGclzFHgXt1TNHL845gBKqrESal2DaTc0gWf4Saja641WBHHc5Iy9nAfysI+h3y tyKSkF84mSWmuXD931pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSI33-0063p3-Qj; Wed, 15 Feb 2023 13:42:13 +0000 Received: from mga09.intel.com ([134.134.136.24]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSI30-0063nC-FA for linux-arm-kernel@lists.infradead.org; Wed, 15 Feb 2023 13:42:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676468530; x=1708004530; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OfvVPmKieXxT2rYuS54QMKMYJwHh1yFcw/O7wIHB3jw=; b=hBGkfLsmsnwREYANmtD4UxaiFjrsoKaW13ZpCrHpa8l7BZuWr84p9ili ypOAvDI6TDWDSjs5yTTXKXyFrVZQ8NnE7Na/up456fd9IeNhFYTdT+SUT TbNYPixEqpF65j+Fyg1nHpcGj3Us/Gh+km5haIFsuUpGffs/bMD8ICc8z QdqG9OYAiCB/9PHJeIM7zXPKourb3pG5f1QVyjqP3gATxgeXQpazqzf1O 2/nyPFt7F7fYw5qSH+v5sycgSqKvuCwKIHt45urN24AqNGdg+PbYJ55SR PnoYPsCHWJMaeHK7VR03nYkuhZ0ydIM29bougZHBaJBlPTYSPxp7D0T3e w==; X-IronPort-AV: E=McAfee;i="6500,9779,10621"; a="332734627" X-IronPort-AV: E=Sophos;i="5.97,299,1669104000"; d="scan'208";a="332734627" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 05:42:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10621"; a="812450032" X-IronPort-AV: E=Sophos;i="5.97,299,1669104000"; d="scan'208";a="812450032" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 15 Feb 2023 05:42:04 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4999593; Wed, 15 Feb 2023 15:42:44 +0200 (EET) From: Andy Shevchenko To: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/5] pinctrl: at91: use devm_kasprintf() to avoid potential leaks (part 2) Date: Wed, 15 Feb 2023 15:42:38 +0200 Message-Id: <20230215134242.37618-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230215134242.37618-1-andriy.shevchenko@linux.intel.com> References: <20230215134242.37618-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230215_054210_619866_E1048426 X-CRM114-Status: GOOD ( 17.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Linus Walleij , Ludovic Desroches , Andy Shevchenko , Claudiu Beznea Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use devm_kasprintf() instead of kasprintf() to avoid any potential leaks. At the moment drivers have no remove functionality hence there is no need for fixes tag. While at it, switch to use devm_kasprintf_strarray(). Signed-off-by: Andy Shevchenko Reviewed-by: Claudiu Beznea Tested-by: Claudiu Beznea --- drivers/pinctrl/pinctrl-at91.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c index 2e7debb905d5..5c01765c7a2a 100644 --- a/drivers/pinctrl/pinctrl-at91.c +++ b/drivers/pinctrl/pinctrl-at91.c @@ -18,6 +18,7 @@ #include #include #include +#include /* Since we request GPIOs from ourself */ #include @@ -1371,6 +1372,7 @@ static int at91_pinctrl_probe_dt(struct platform_device *pdev, static int at91_pinctrl_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct at91_pinctrl *info; struct pinctrl_pin_desc *pdesc; int ret, i, j, k; @@ -1394,9 +1396,19 @@ static int at91_pinctrl_probe(struct platform_device *pdev) return -ENOMEM; for (i = 0, k = 0; i < gpio_banks; i++) { + char **names; + + names = devm_kasprintf_strarray(dev, "pio", MAX_NB_GPIO_PER_BANK); + if (!names) + return -ENOMEM; + for (j = 0; j < MAX_NB_GPIO_PER_BANK; j++, k++) { + char *name = names[j]; + + strreplace(name, '-', i + 'A'); + pdesc->number = k; - pdesc->name = kasprintf(GFP_KERNEL, "pio%c%d", i + 'A', j); + pdesc->name = name; pdesc++; } } @@ -1797,7 +1809,8 @@ static const struct of_device_id at91_gpio_of_match[] = { static int at91_gpio_probe(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; struct at91_gpio_chip *at91_chip = NULL; struct gpio_chip *chip; struct pinctrl_gpio_range *range; @@ -1866,16 +1879,14 @@ static int at91_gpio_probe(struct platform_device *pdev) chip->ngpio = ngpio; } - names = devm_kcalloc(&pdev->dev, chip->ngpio, sizeof(char *), - GFP_KERNEL); - + names = devm_kasprintf_strarray(dev, "pio", chip->ngpio); if (!names) { ret = -ENOMEM; goto clk_enable_err; } for (i = 0; i < chip->ngpio; i++) - names[i] = devm_kasprintf(&pdev->dev, GFP_KERNEL, "pio%c%d", alias_idx + 'A', i); + strreplace(names[i], '-', alias_idx + 'A'); chip->names = (const char *const *)names; -- 2.39.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel