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++; } }