From patchwork Thu Dec 16 16:22:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12696508 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 58980C433EF for ; Thu, 16 Dec 2021 16:34:42 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=KKrQ8vfWTHPpB+zJrrm5KEkxgmwOqrgchITiR10lF3Y=; b=iMOtyJzzrQBSWU J4JEjGPaHlm0xdYB31mfzIw18sxedrg+6RZRZfUIuYLWTyFTLtPLpxxry3Qz6DiHZTffe0i0blgBu Jhke5iZTUmyZu2FW+kVaDsSB8UA8FblAqDZxQ7r0Vg4yCu/AuzZd+h+YHGOgDK6oXnosmAXP70Tua QrmdX1FEI+MQB/W7AGH4Loa6fnsrZcUPGKf+ukWCgsKwh9PsJwEvxbz/T15S7p2vCZmPVkoAMtYOy vvfxxvdsq8S/kUVu0M1NT9Wf2Mp2GibGkcMibH8FZ5nhQupvqwGQn5FwBhw5Mr7TMNoq4xf2lnSip okV8fB6BV3O3OCpKAKow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtgU-006dZF-F6; Thu, 16 Dec 2021 16:32:48 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtWI-006aER-Pg for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 16:22:16 +0000 Received: by mail-lj1-x22f.google.com with SMTP id v15so39408033ljc.0 for ; Thu, 16 Dec 2021 08:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4lWtkWUkkW3ND3RjcGaqJdo8TrrjuOiBcKkAeDb9fTo=; b=X19CCWSHn+YUHSaTyIW1WkzS0qn/tl30Lmbqg5N7OydTWstDVDYHDH22bqmTE4S4Rk 5U0jsh8xNoewi0aeZ8t3LbOALo5ol45GHayFSqWcgvO1q1p2zXwHxD79ClnJPmlDPMgQ 0TJ/LQ3mKJTaWy/tNmXDdGCaQvRNE0rAYzxPav3wRBLSnUZh9s7/vvMp26kTog9mQql/ oexJaqt8KdTpN2iRmXEbWgA4ij/rjeDjSRYz/tRgvFYA60JLCiWfmrBGvfbfWdIZHNJ1 No6qAASzU1mJZZL2Pf90U0jWc1fI/1S/ohuiwXZG+boKRlTTZMBsniLW5n+Nz+1y1zi2 IVsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4lWtkWUkkW3ND3RjcGaqJdo8TrrjuOiBcKkAeDb9fTo=; b=BgxDK+eTlIfQuVEZhIJtOHi/qs9eJ2Y5NKC2mQzRob3SeoKsJnJ9tc0ggpQE9GX401 9uPQwfu0I5jYni/P68sWMpWNdu4c+CTEqWku3wgHa6ZPRtb9NksdTtcsuHnvt6wXfTrS FyprN6t6COTGnebMDaPTr2m9vr5W1BtFAbnmIFSkGotQd8874jCgQWBg3VyGQ98+MVTM 6rekV7YnV8hzAWFnNRGPqX6DwKE274nJhHdkMRYEU8s1EPV7Tz/67WYBgreft3WSLkdl NDZfetFCFlADP/0jQTPD0t2xj2ZORswY4n2jpcmfKzhHWFJkGphlCLnb3TjpeeFHKebZ sn/A== X-Gm-Message-State: AOAM5316pSKNgrvCBWQM2ZiJEtiuhAAqIxt57VeE4+FoojUFq7d5U6Mu oV+rHMCkkPMosLsHLXz3AJI= X-Google-Smtp-Source: ABdhPJw7w293M7f00o/g7bhxbJz0jq9qzwJ29MYFqBPAHxUkJMWnG8RqduvBa2CVLAnpR9T+cSbrfQ== X-Received: by 2002:a2e:8502:: with SMTP id j2mr16129822lji.191.1639671732555; Thu, 16 Dec 2021 08:22:12 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id s13sm938623lfg.126.2021.12.16.08.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 08:22:12 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij Cc: Dong Aisheng , Fabio Estevam , Shawn Guo , Stefan Agner , Pengutronix Kernel Team , Sascha Hauer , NXP Linux Team , Lakshmi Sowjanya D , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 1/4] pinctrl: imx: prepare for making "group_names" in "function_desc" const Date: Thu, 16 Dec 2021 17:22:03 +0100 Message-Id: <20211216162206.8027-1-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_082214_885403_E47BF72D X-CRM114-Status: GOOD ( 12.27 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki The plan for "struct function_desc" is to make its "group_names" /double/ const. That will allow drivers to use it with static const data. This imx change is required to avoid: drivers/pinctrl/freescale/pinctrl-imx.c: In function 'imx_pinctrl_parse_functions': drivers/pinctrl/freescale/pinctrl-imx.c:672:24: error: assignment of read-only location '*(func->group_names + (sizetype)(i * 4))' 672 | func->group_names[i] = child->name; | ^ Signed-off-by: Rafał Miłecki --- drivers/pinctrl/freescale/pinctrl-imx.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c index daf28bc5661d..47b2ab1a14d0 100644 --- a/drivers/pinctrl/freescale/pinctrl-imx.c +++ b/drivers/pinctrl/freescale/pinctrl-imx.c @@ -648,6 +648,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np, struct device_node *child; struct function_desc *func; struct group_desc *grp; + const char **group_names; u32 i = 0; dev_dbg(pctl->dev, "parse function(%d): %pOFn\n", index, np); @@ -663,14 +664,16 @@ static int imx_pinctrl_parse_functions(struct device_node *np, dev_err(ipctl->dev, "no groups defined in %pOF\n", np); return -EINVAL; } - func->group_names = devm_kcalloc(ipctl->dev, func->num_group_names, - sizeof(char *), GFP_KERNEL); + + group_names = devm_kcalloc(ipctl->dev, func->num_group_names, + sizeof(char *), GFP_KERNEL); if (!func->group_names) return -ENOMEM; + for_each_child_of_node(np, child) + group_names[i] = child->name; + func->group_names = group_names; for_each_child_of_node(np, child) { - func->group_names[i] = child->name; - grp = devm_kzalloc(ipctl->dev, sizeof(struct group_desc), GFP_KERNEL); if (!grp) { From patchwork Thu Dec 16 16:22:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12696509 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 788D5C433F5 for ; Thu, 16 Dec 2021 16:36:11 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bNs3+CTUWzeZz/TQ4vKSRX26o15W8OZej0sEeafVT3Y=; b=UkpqWN//VnB/7a cnEaUT9a9zfPIIDf6pPn+CshHc/ud6W1BB3+q63Xu4ZA2FBUzWt7r0qXcuNKviWhYnlsl5iaUCAr5 +FfQ/xpG8Aw89B0Fbo9oK9Q+M7/w02XGY7hYPKP743CcL/ifM+wBk9qWMpzqfI0R18PQNARyJ3XNb 5np5wSp5uwJU7ykz5IAAP3CDM8aksCDDpZMoF56kl8LQ0dtqGtB8VhPn/FpWGOwF8yUED8GIuiaxr PGJb91KYobP9w3NQgC/qSjYitpWsxk+eLU6MuEdeDMJX5uSiw+4YaFXn37SOkD8qaei7Xxg5BKcvo Rkleedw8ZIy6O2enhrBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxthx-006e27-Um; Thu, 16 Dec 2021 16:34:19 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtWK-006aFK-MD for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 16:22:18 +0000 Received: by mail-lf1-x12b.google.com with SMTP id bt1so8043752lfb.13 for ; Thu, 16 Dec 2021 08:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eh4pCHYG63YtXHQZCJTnWwo2iBYp9kjwNNdMHaucw5Q=; b=fPLe2/u42DDLMx0iB16nZYh9AfEYpFp4s0rh8zfujdC2CePA9JZTqXTRWa04yVyTxW HscHKgsLTAHi8xckF3aDAKxM4dEOFzP6cDlrhDF9cZpoq8jBCIpy5dWwQCrn7TI4XRog 7E7+914InnilU9q5yc/iYZApYbFTd8iCdymmJrawOAgbNulgzEtKL3ufm4Gz2rlCnQ7z zImCdFy9uRPTxnUxN2zp8wLBHIL/sSK0GLHcusj5qkD1XECIg7ceApYU6/Uceo7PvW7Z TbUy0lzy/PT5Zx+dRPgw2PmECGCabB1UTyE2po+MQag46KmtjpfZEl5xzPqPSj6aOQcW vPxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eh4pCHYG63YtXHQZCJTnWwo2iBYp9kjwNNdMHaucw5Q=; b=RZnhPhmf7yZDRBGwDLnTvVvF5+rcElUPYSAUeM5KvVCaeq9US6i4hn+EPeqXX1bJ11 kSwc3nQqy9uhdiq7RW9ZowQaxweBCCpXGAVmn7CmX6v5EtyHP6B7hT2TWvVr0HgshbHf NbUJlMZyhbwUMPR+w0Ur/gV0FU9o7L9vlb9phmqf6N8nUrbiB9L73r2gavg+JGNtshlb 0IotjV3JEfPQSqt3y9TpAYO1grIQTi+T7JeRI7vQWQm4hXnMH7CU2VIQ6lt2UpiT8mEj HsMaCaaTru0/QIxoR4KNG1JCAqZaf20qMbR7GkmjjhWKuTP63l4DnPSd7f7i3vgPCvAm 9ElQ== X-Gm-Message-State: AOAM530mrfpso243kOtFVRjW9+hGz289vAO4HLX7O6n2PkWftnHIArD4 2Xmj9JX2+k5GzBABNNVC3wo= X-Google-Smtp-Source: ABdhPJxMjbzMoRUBrzIg94c1Lw32sycpZUKjsGYCnfQFZX3Qb970kRzwEpOc8A2H2v43VveauqE8LQ== X-Received: by 2002:a05:6512:3a91:: with SMTP id q17mr14672499lfu.425.1639671734417; Thu, 16 Dec 2021 08:22:14 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id s13sm938623lfg.126.2021.12.16.08.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 08:22:14 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij Cc: Dong Aisheng , Fabio Estevam , Shawn Guo , Stefan Agner , Pengutronix Kernel Team , Sascha Hauer , NXP Linux Team , Lakshmi Sowjanya D , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 2/4] pinctrl: keembay: comment process of building functions a bit Date: Thu, 16 Dec 2021 17:22:04 +0100 Message-Id: <20211216162206.8027-2-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211216162206.8027-1-zajec5@gmail.com> References: <20211216162206.8027-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_082216_784200_8CCCD82F X-CRM114-Status: GOOD ( 16.90 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki This should make code a bit easier to follow. While at it use some "for" loops to simplify array iteration loops. Signed-off-by: Rafał Miłecki --- drivers/pinctrl/pinctrl-keembay.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c index 2bce563d5b8b..9a602abad8df 100644 --- a/drivers/pinctrl/pinctrl-keembay.c +++ b/drivers/pinctrl/pinctrl-keembay.c @@ -1617,37 +1617,38 @@ static int keembay_build_functions(struct keembay_pinctrl *kpc) struct function_desc *keembay_funcs, *new_funcs; int i; - /* Allocate total number of functions */ + /* + * Allocate maximum possible number of functions. Assume every pin + * being part of 8 (hw maximum) globally unique muxes. + */ kpc->nfuncs = 0; keembay_funcs = kcalloc(kpc->npins * 8, sizeof(*keembay_funcs), GFP_KERNEL); if (!keembay_funcs) return -ENOMEM; - /* Find total number of functions and each's properties */ + /* Setup 1 function for each unique mux */ for (i = 0; i < kpc->npins; i++) { const struct pinctrl_pin_desc *pdesc = keembay_pins + i; - struct keembay_mux_desc *mux = pdesc->drv_data; + struct keembay_mux_desc *mux; - while (mux->name) { - struct function_desc *fdesc = keembay_funcs; + for (mux = pdesc->drv_data; mux->name; mux++) { + struct function_desc *fdesc; - while (fdesc->name) { + /* Check if we already have function for this mux */ + for (fdesc = keembay_funcs; fdesc->name; fdesc++) { if (!strcmp(mux->name, fdesc->name)) { fdesc->num_group_names++; break; } - - fdesc++; } + /* Setup new function for this mux we didn't see before */ if (!fdesc->name) { fdesc->name = mux->name; fdesc->num_group_names = 1; fdesc->data = &mux->mode; kpc->nfuncs++; } - - mux++; } } From patchwork Thu Dec 16 16:22:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12696510 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 B02B6C433EF for ; Thu, 16 Dec 2021 16:37:33 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t4sPwljEb1WWjZAhAY23h6Og3skcefOtbPCP+qA9e8M=; b=QsY9T654fPsF8n 7K/XdQ8uaD8Q0KIzk8FCxNoiZKCFvL0xjkfnaCjcmyjc/BzKoUeNbasNDJwliwd7qULO4Geuf0Kt4 oViS3gqwDqTi6sZr0ozoPSj1pPDTtMa15s+AfSWCU0P9vQKdp4yUqig+N69giAetxKqSKd0nPnbQZ j94ZDd+NxF8V0IaSAGyAvby50OtRCT53jKsUNzJWbQjFBX02Hj65wIbeYUbS5q1lUjcghPRZ2Mgr+ N9A9ZHZuYJg6tfpwHZihtNAHX543e0jSCLlTVUaghUN3nTvDmUV827uv+rsTxs2iWzTP2A63NeZTW B1c3iziejDFWIOFJrSog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtjN-006eXT-By; Thu, 16 Dec 2021 16:35:46 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtWM-006aFy-2Y for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 16:22:19 +0000 Received: by mail-lj1-x230.google.com with SMTP id u22so39275499lju.7 for ; Thu, 16 Dec 2021 08:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lUnqODC8l6jXMRXSjWHaW3K51f2Zp3o4i2EaGR4+YbQ=; b=lvXiAF1d3Vs6sdW3IGqJJAUJXmkC98UgqlCJXdWz4XRv6C+B2cDS1Bf41kUY0g2Zkz xYZiJ+HHUlS4YHH4irezA1s/Xn+KoDL/90rVDnGDTT2oHgjhwqlmlSy6cNxnvxCmw9lO vFJlw0d5k4Oj5l64lX3jLconjiLdN2tEcyHmnUuH3Rcqdow/Rm841YmWY7Awofrw+RIh 1kZHNv+RMH2gYu8zKPOiMijlsd6RYSAv4g5ocOwpMStnlo/T3wEOXp6aOx6/tcbtfJNO V3Zh0jJQkwhculKk8tpYf4EqFP6MnmJRJ2Cn9v97qeNzMfDNimWbJ1u8zbKQJ92rtnrs YTUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lUnqODC8l6jXMRXSjWHaW3K51f2Zp3o4i2EaGR4+YbQ=; b=07g0EjWpHMXj/+SfMKxWOC+j+VkM2oqVSZhQ+feVdK1UDs5l0eIb9PFktdSMbeSnE4 INN4aBgUQViwNkr0SiPhi6FhToQUkQzIuhK9PgA8Jf3OBFguDc7n9paVOoTwux4KuNxx ReflWyN3lUKtgBohu5avayLlF+7mD9mplhSunWK8NRNWUbrdFBZ9SDZHOnOq5idviHNN z6tgb52f6F1TrsRxMd15Yk27s4zV0KVeOvX52kHVNYpjfSgbqorT3occhNI7kqGA6BaP qqcoL5XzxUHEscYCiXZ6PibAC7mHxiTvc0KE+W22oSH5bk3i/FlGSa71IspJ83UUqBV8 muQQ== X-Gm-Message-State: AOAM531rqowqgiMkKNBdmO49mHdXE/JGahV62Y/1zAh/5PJF79pE8Vrd vXPaBZSwJ+px/fz66f/F5qA= X-Google-Smtp-Source: ABdhPJwCahoizSn2WH15Q57HOXkXWNpk/FmVvJXcE9B0YnDgR8bHY5REokQAOeCUiLKOMPZGnP+GsA== X-Received: by 2002:a2e:5d6:: with SMTP id 205mr15153216ljf.270.1639671735855; Thu, 16 Dec 2021 08:22:15 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id s13sm938623lfg.126.2021.12.16.08.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 08:22:15 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij Cc: Dong Aisheng , Fabio Estevam , Shawn Guo , Stefan Agner , Pengutronix Kernel Team , Sascha Hauer , NXP Linux Team , Lakshmi Sowjanya D , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 3/4] pinctrl: keembay: rework loops looking for groups names Date: Thu, 16 Dec 2021 17:22:05 +0100 Message-Id: <20211216162206.8027-3-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211216162206.8027-1-zajec5@gmail.com> References: <20211216162206.8027-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_082218_167803_D9B8A912 X-CRM114-Status: GOOD ( 19.67 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki Make the outer loop iterate over functions as that's the real subject. This simplifies code (and reduces amount of lines of code) as allocating memory for names doesn't require extra checks anymore. While at it use local "group_names" variable. The plan for "struct function_desc" is to make its "group_names" /double/ const. That will allow drivers to use it with static const data. This keembay "group_names" change is required to avoid: drivers/pinctrl/pinctrl-keembay.c: In function 'keembay_add_functions': drivers/pinctrl/pinctrl-keembay.c:1594:8: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1594 | grp = func->group_names; | ^ Signed-off-by: Rafał Miłecki --- This has been runtime tested. I verified that output of /sys/kernel/debug/pinctrl/*/pinmux-functions is the same without and with my patches. --- drivers/pinctrl/pinctrl-keembay.c | 66 ++++++++++++------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c index 9a602abad8df..152c35bce8ec 100644 --- a/drivers/pinctrl/pinctrl-keembay.c +++ b/drivers/pinctrl/pinctrl-keembay.c @@ -1555,58 +1555,42 @@ static int keembay_pinctrl_reg(struct keembay_pinctrl *kpc, struct device *dev) } static int keembay_add_functions(struct keembay_pinctrl *kpc, - struct function_desc *function) + struct function_desc *functions) { unsigned int i; /* Assign the groups for each function */ - for (i = 0; i < kpc->npins; i++) { - const struct pinctrl_pin_desc *pdesc = keembay_pins + i; - struct keembay_mux_desc *mux = pdesc->drv_data; - - while (mux->name) { - struct function_desc *func; - const char **grp; - size_t grp_size; - u32 j, grp_num; - - for (j = 0; j < kpc->nfuncs; j++) { - if (!strcmp(mux->name, function[j].name)) - break; - } - - if (j == kpc->nfuncs) - return -EINVAL; - - func = function + j; - grp_num = func->num_group_names; - grp_size = sizeof(*func->group_names); - - if (!func->group_names) { - func->group_names = devm_kcalloc(kpc->dev, - grp_num, - grp_size, - GFP_KERNEL); - if (!func->group_names) - return -ENOMEM; + for (i = 0; i < kpc->nfuncs; i++) { + struct function_desc *func = &functions[i]; + const char **group_names; + unsigned int grp_idx = 0; + int j; + + group_names = devm_kcalloc(kpc->dev, func->num_group_names, + sizeof(*group_names), GFP_KERNEL); + if (!group_names) + return -ENOMEM; + + for (j = 0; j < kpc->npins; j++) { + const struct pinctrl_pin_desc *pdesc = &keembay_pins[j]; + struct keembay_mux_desc *mux; + + for (mux = pdesc->drv_data; mux->name; mux++) { + if (!strcmp(mux->name, func->name)) + group_names[grp_idx++] = pdesc->name; } - - grp = func->group_names; - while (*grp) - grp++; - - *grp = pdesc->name; - mux++; } + + func->group_names = group_names; } /* Add all functions */ for (i = 0; i < kpc->nfuncs; i++) { pinmux_generic_add_function(kpc->pctrl, - function[i].name, - function[i].group_names, - function[i].num_group_names, - function[i].data); + functions[i].name, + functions[i].group_names, + functions[i].num_group_names, + functions[i].data); } return 0; From patchwork Thu Dec 16 16:22:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12696511 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 D066CC433F5 for ; Thu, 16 Dec 2021 16:38:33 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4b1oiHPrs+OB6uAdy0b4AhbgnllPG3Ob5ldBzIGoAoA=; b=P86N8HhtzszCyR hkX08qw1IX/KMWaaCq/OBBHumy3OaFxY8L9ueZITxk6FHZtC0a6GIsEpu7wY5jvzgBBNzSdG9fz5U eaSZseXOqgup/d2t9Nnx8vyHB4t12KoLUNfIDV/umARps+uC81GD0Q3zK5xhPd0ucLVLHkp4ZNaR7 qufAfuOYQyHtUSszvTxKdPsGGtNxUanFR+5SkL2b3qV7tAFsk2EAUkx/h16pmkhlgdWQ9melLpTTN VLYdNNruTdrDB5I+GVlvOI7fty9OminkfOybKSCCrpue94pXXpKO3g7k30OZBgkKhsjgoYZjfV5zv jIXEWGn4yQgcbsyBLoBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtkV-006eri-Dx; Thu, 16 Dec 2021 16:36:56 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxtWO-006aHE-6Q for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 16:22:21 +0000 Received: by mail-lj1-x22d.google.com with SMTP id a37so38220903ljq.13 for ; Thu, 16 Dec 2021 08:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JUJgiOCeEkvWRBfsS4oHMEMSHGIv4GiMwDTH+LmBGxo=; b=IoU2buhjcjWp2q7dTYztQ+qpX9khq7w3X58Xw/LgcxE4PGjKWNNhJYajACUrAVTjAV 0pAehz9KDe0vabDtPwrPpT5+5cx+ekArogFvQRRudrAEWggcwLdZ9jDNqkfX2O7EeYVj VXLvZmB/auujRtxBKEHPiF6EEMSOYd/nEJJMPgB6kgGx2Q+TTohdHLGqTj/EK8/ACs5B qqm/a36vKUR5A3lsXy1FMwKyEZ0YhoCgw3aiidLX52s9PVy2Uy8rleHC+KwfQqeTYfc2 30yXUfz4MzD+gAr1XW3ghh9tEAPdLXsn7sJR5hhgn4lJYW4+eeg5AWWBs+W9MPVFrBT1 mCTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JUJgiOCeEkvWRBfsS4oHMEMSHGIv4GiMwDTH+LmBGxo=; b=JS0F5NFrkYungWcDpT6gXyYjIECv6zBvTH50NvbY8H80WQ4EQUn4ffhVvg4+54fRqp KlHcsDYvFPfXZ6tMTr58TYYcUetg6sVe5xekjVLaaScRqgoJyT5e+Bj0KiAmZxeUjDws KjW6Fxh8/fAiOSGvtwwCqghbk6/QG6ftY8nUWIGiAwMpIGgIgdbLH323JrtnwGIxwqC4 F/XRci/ykaUxtslaoc6d8Qn49vF2lx0rDGh7wUzsO0Lf6x6S5jjuIC5bJ8IkN+HCNZWP C96IbojUt8VUVAuNdJ8j0ZqZb36ZNDp/LCiOlQhR/MtpsMOJr191rOFrMHoRyVi3GxS7 9a/Q== X-Gm-Message-State: AOAM530Fp0+adK7q3bW6R5DNup3sAEPBlY+pFnVz/ThNcDVnBLQxHpOb OcjuSMGpH3hWXLh2Oojn6xA= X-Google-Smtp-Source: ABdhPJyrGXI7ioAaKnKKAK2OC5i6FS7Rxk9DNehos53wIcXBnCY1INj+5OTISTqtn/SLfMS9qHQipg== X-Received: by 2002:a2e:bd0e:: with SMTP id n14mr15323654ljq.159.1639671737725; Thu, 16 Dec 2021 08:22:17 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id s13sm938623lfg.126.2021.12.16.08.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 08:22:17 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij Cc: Dong Aisheng , Fabio Estevam , Shawn Guo , Stefan Agner , Pengutronix Kernel Team , Sascha Hauer , NXP Linux Team , Lakshmi Sowjanya D , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 4/4] pinctrl: add one more "const" for generic function groups Date: Thu, 16 Dec 2021 17:22:06 +0100 Message-Id: <20211216162206.8027-4-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211216162206.8027-1-zajec5@gmail.com> References: <20211216162206.8027-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_082220_310114_2E469174 X-CRM114-Status: GOOD ( 13.68 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki Generic code doesn't modify those strings and .get_function_groups callback has that extra "const" as well. This allows more flexibility in GENERIC_PINMUX_FUNCTIONS users. Signed-off-by: Rafał Miłecki --- drivers/pinctrl/pinmux.c | 2 +- drivers/pinctrl/pinmux.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 6cdbd9ccf2f0..f94d43b082d9 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -875,7 +875,7 @@ EXPORT_SYMBOL_GPL(pinmux_generic_get_function); */ int pinmux_generic_add_function(struct pinctrl_dev *pctldev, const char *name, - const char **groups, + const char * const *groups, const unsigned int num_groups, void *data) { diff --git a/drivers/pinctrl/pinmux.h b/drivers/pinctrl/pinmux.h index 78c3a31be882..72fcf03eaa43 100644 --- a/drivers/pinctrl/pinmux.h +++ b/drivers/pinctrl/pinmux.h @@ -129,7 +129,7 @@ static inline void pinmux_init_device_debugfs(struct dentry *devroot, */ struct function_desc { const char *name; - const char **group_names; + const char * const *group_names; int num_group_names; void *data; }; @@ -150,7 +150,7 @@ struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev, int pinmux_generic_add_function(struct pinctrl_dev *pctldev, const char *name, - const char **groups, + const char * const *groups, unsigned const num_groups, void *data);