From patchwork Thu Nov 17 21:11:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 21923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp626661wrr; Thu, 17 Nov 2022 13:17:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vXuVDrVH4vBVnWiT1lo7/tr8FW12P3LzcNAUUb8Xalv/nsN7k+J+f4g7iUMzA7mVvZfJc X-Received: by 2002:a17:906:fd2:b0:78d:9c2f:bf78 with SMTP id c18-20020a1709060fd200b0078d9c2fbf78mr3681475ejk.594.1668719833188; Thu, 17 Nov 2022 13:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668719833; cv=none; d=google.com; s=arc-20160816; b=sD//99JyAe2h+43ziQl5BB4snoxkqIFfdNgtKukV2ceFG8XdX6dv9TYV0RInMrW6YF PWjtixw0wxWhirVwHgWsXBIHCPbCghSbktERKRyIF3tfYvD8CTPYeV3Li8rWh4Vj7A4U 5QHfeqSFpg/TdMxeIhsmjkqEDPMvioJ4G7hlLHxLp4HGPb5gw6/m66igUKkUxmEroOgf HH3x1H7oO7NDb80FgkrmpwFta8FiY9fijuvvBo4ezX2TettSsJxkRdjP/0bhPtSNRpB4 hwKw0GxLJAcGqzDT35jZlOraJuE/5jUuNuo04Te35nHd5cl4IBJGdgwyGZ9J8eVQNimN dF6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=I6TdSFUMHQYtQrUKhlJEuqkXetBBh8OTvkACsKsZnuI=; b=rKCtpgr67cm0cw2vAWN8vjiCrt4ErwhG2ziIsVT8RKaHEr5NENwT4liKX4D+Jk8ADd YkZaYwBny7ul4nV4w04JxEJiNtqMi3YVZs3sXEOpL9QfB9GaselqpqUKswqb8WVwBGCK X520k5huC7Rz0OITZ1Qph3Q7QHkZsuq5Q88Abm/cssI+05/DkxR4RQO3bVOdkKH5z+jI yTspa6lwaM+UTua0IyVXGgibI2XxUwxwd5gxtyGPStv0XuoL71HUb7s77aDLdtxAkRCk jxjFjTzeVij3F7hSLd2uQzmVVdR5RvUBmD7NAEM/mpaOU66Pqk49sig/iQMWh+oy4IT3 XOHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a05640211ce00b00456eaa4fb1fsi1785327edw.223.2022.11.17.13.16.26; Thu, 17 Nov 2022 13:17:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240580AbiKQVMG (ORCPT + 99 others); Thu, 17 Nov 2022 16:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240736AbiKQVL5 (ORCPT ); Thu, 17 Nov 2022 16:11:57 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C7DE22283 for ; Thu, 17 Nov 2022 13:11:56 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovmAp-0007On-Uh; Thu, 17 Nov 2022 22:11:52 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ovmAo-004v5m-6M; Thu, 17 Nov 2022 22:11:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ovmAo-00HN0F-Dh; Thu, 17 Nov 2022 22:11:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 1/4] pwm: Document variables protected by pwm_lock Date: Thu, 17 Nov 2022 22:11:40 +0100 Message-Id: <20221117211143.3817381-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> References: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1336; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=gVppIEf/lpbSlfN4FOCkWayRJhongp4knJTqk4NtP9Q=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBjdqN+8HG4Bay2je5Xh/cc1bSrfdvdcwF88fPwunKV FGDfVEKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY3ajfgAKCRDB/BR4rcrsCZV5B/ 9+W4jlFDJayYkJPKxcszuItsiylo7wpidxU8YNXE9cYbwpw9aXu/eJ8gOOAjfs5i6/+QoofiLTTGkt 5CYqgvRLMpgvNir2eQKwgkINkJIvlzJQUzmnTTFJeTbpgi/RgfHDUszIXPQyEbgCXAXMDgiLo4UUBr c5kcgAICd0yyNvgELU6yXEzSvrUTNx3AXKzIhCl+Xsd81KTD/thUy6CqvlVYwEN3AAdlMs37u1lwkU cbsGobvw+yqbpoVuZ3+RHpOEZuyx+vjQ5VBsWSbLoKiFlxngfmULjIYCVWHfXVTBaLcl3ygzE/Y5ja Ieu0+bMI2x6YndkGlNKIHmqZPv+XNh X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749779567822581624?= X-GMAIL-MSGID: =?utf-8?q?1749779567822581624?= To simplify validation of the used locking, document for the global pwm mutex what it actually protects against concurrent access. Also note for two functions modifying these that pwm_lock is held by the caller. Reviewed-by: Andy Shevchenko Signed-off-by: Uwe Kleine-König --- drivers/pwm/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index d333e7422f4a..ebe06efe9de5 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -27,7 +27,10 @@ static DEFINE_MUTEX(pwm_lookup_lock); static LIST_HEAD(pwm_lookup_list); + +/* protects access to pwm_chips, allocated_pwms, and pwm_tree */ static DEFINE_MUTEX(pwm_lock); + static LIST_HEAD(pwm_chips); static DECLARE_BITMAP(allocated_pwms, MAX_PWMS); static RADIX_TREE(pwm_tree, GFP_KERNEL); @@ -37,6 +40,7 @@ static struct pwm_device *pwm_to_device(unsigned int pwm) return radix_tree_lookup(&pwm_tree, pwm); } +/* Called with pwm_lock held */ static int alloc_pwms(unsigned int count) { unsigned int start; @@ -50,6 +54,7 @@ static int alloc_pwms(unsigned int count) return start; } +/* Called with pwm_lock held */ static void free_pwms(struct pwm_chip *chip) { unsigned int i; From patchwork Thu Nov 17 21:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 21927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp627175wrr; Thu, 17 Nov 2022 13:18:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf4d5duVQruRFIDTY9c/T/ETDspzMAzWlkjD6SHWar0Cu1I8btyLKwOxIfudul1YhIwtIWBl X-Received: by 2002:a17:906:a107:b0:77f:9082:73c7 with SMTP id t7-20020a170906a10700b0077f908273c7mr3506221ejy.517.1668719909453; Thu, 17 Nov 2022 13:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668719909; cv=none; d=google.com; s=arc-20160816; b=pjER3aJzQvQFNxfXl0vK9Lu3vokmD9kItw1gc2FNO68pm/Bw7F08l8G34ckLsnE+7v wSyEoCoGV/nXHbQn84W/ue67GVSSv4XjHAoUqriYmzjen+Njvj3VrAaIQoInBewRw3g3 391kJUc+JGe5532vV2HNCntid57b4IBlumo/b+vfGx6iTepnAkeGne9rsI/dO47TV37c D/S++JoV0/YDhhYfnbWuixekQj2lUEhoK+gGDxN6nGiL3PXamVrdCssS7cVrCeKO7bSL oYEfmqxUyrnXDZD4mCqqck6liC7+hlW5emjWxb5h5naCuiknAh6/UO4eiwTThGU4FXXt 1bog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7iI3TEtuLXYEVHITOK+IZnagb5NR1KjnvnwaZoqknc4=; b=CavBNtnM3IC9LTBpPCY5IVrvnaNM/L9/76agVD2YoYZsjfab1VrUrtlPqG1GB/AeqO Ne3sh/i4MURIQCQjpmqGxPlbQKqUlPqSfaDme8MuxmiAC5cLnoSUfWj1/00TFvVfWFj2 yvNm42j+CGni8eM4yizGHV9kifXGW7I7qnxNu57DgMROwje13t9VEuG7m/0fhG/HJeI6 5AaXgnobTXGTACS+pogsS8cEtrLnO1lc9DgLtlhLAxGMTZZLdafyd5EobKrOkPtRVQxR CanFcbEuoKInQRkhNaJXwgnaV5OBV5W6a1Buqkd4RqFXTSY3jJjG6piG6NSHYXJpMt3Z 7Dwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc34-20020a17090716a200b007ae9f42f878si1714643ejc.354.2022.11.17.13.18.00; Thu, 17 Nov 2022 13:18:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240766AbiKQVML (ORCPT + 99 others); Thu, 17 Nov 2022 16:12:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240721AbiKQVL5 (ORCPT ); Thu, 17 Nov 2022 16:11:57 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551C620182 for ; Thu, 17 Nov 2022 13:11:56 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovmAp-0007Oo-Uf; Thu, 17 Nov 2022 22:11:51 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ovmAo-004v5p-80; Thu, 17 Nov 2022 22:11:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ovmAo-00HN0I-Km; Thu, 17 Nov 2022 22:11:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 2/4] pwm: Reduce time the pwm_lock mutex is held in pwmchip_add() Date: Thu, 17 Nov 2022 22:11:41 +0100 Message-Id: <20221117211143.3817381-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> References: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1801; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=W5msw8zxagwiJj6hJi4SU67DWQ0AjhZfTFm/qYmXeAw=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBjdqOBYckSnoEgissL+BaN7xiZzh9ivhj1/pMXWrvx 7N8xgGaJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY3ajgQAKCRDB/BR4rcrsCXo5B/ 0dktt/af+nBKYFHSIzUWzlrkfNaF39SwKZymqqNFesWnRgx5Bme1h08zFbNC/AiGiSHNoO0ZLUqWvD wSwuRbHHcanZJzaITHzqoKV1LB0HQP5+czqi39f1uyXmDd7zzNf7MVPsHU9KSBRv+VJeq1Nf2OCelT Dp5XHO6a1Eq/oLfVtkOu1Fejl47Hn9yUjFgjYDYcx9g4r8Fl11kzajFwA3A4/1hIXbe6qXg3U7n9QO atAsT6jYdTRua1p3eY7s/nsD6RbMruUuhkUMlYhlfwJ2b1ejYAgK83zp47LjivQN617DWai9oolwqz e+0PtbpKksP+vwSwf6Tu25N2pAWeyO X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749779648145500664?= X-GMAIL-MSGID: =?utf-8?q?1749779648145500664?= This simplifies error handling as the need for goto error handling goes away and at the end of the function the code can be simplified as this code isn't used in the error case any more. Now memory allocation and the call to of_pwmchip_add() are done without holding the lock. Both don't access the data structures protected by &pwm_lock. Reviewed-by: Andy Shevchenko Signed-off-by: Uwe Kleine-König --- drivers/pwm/core.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index ebe06efe9de5..2338119a09d8 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -272,20 +272,21 @@ int pwmchip_add(struct pwm_chip *chip) if (!pwm_ops_check(chip)) return -EINVAL; + chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL); + if (!chip->pwms) + return -ENOMEM; + mutex_lock(&pwm_lock); ret = alloc_pwms(chip->npwm); - if (ret < 0) - goto out; + if (ret < 0) { + mutex_unlock(&pwm_lock); + kfree(chip->pwms); + return ret; + } chip->base = ret; - chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL); - if (!chip->pwms) { - ret = -ENOMEM; - goto out; - } - for (i = 0; i < chip->npwm; i++) { pwm = &chip->pwms[i]; @@ -301,18 +302,14 @@ int pwmchip_add(struct pwm_chip *chip) INIT_LIST_HEAD(&chip->list); list_add(&chip->list, &pwm_chips); - ret = 0; + mutex_unlock(&pwm_lock); if (IS_ENABLED(CONFIG_OF)) of_pwmchip_add(chip); -out: - mutex_unlock(&pwm_lock); - - if (!ret) - pwmchip_sysfs_export(chip); + pwmchip_sysfs_export(chip); - return ret; + return 0; } EXPORT_SYMBOL_GPL(pwmchip_add); From patchwork Thu Nov 17 21:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 21930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp627302wrr; Thu, 17 Nov 2022 13:18:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf58ACECZ78Zz/CE0PrNAPqOFh17bhciqruJHZgHIq+y2jtarU/mfbWUleNZqDBwvZpI1Ohf X-Received: by 2002:a17:906:39c8:b0:7ad:79c0:5482 with SMTP id i8-20020a17090639c800b007ad79c05482mr3468153eje.730.1668719927336; Thu, 17 Nov 2022 13:18:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668719927; cv=none; d=google.com; s=arc-20160816; b=id9efDS5XAfu3D5/MeVBXy+Ppp9SD2ri51LNmwkQzHLLA+WjP//JDoet9G/yMXg4ba okVa5IL0J8pAfkUdHt0LW8+1AQWpOim8oJJcRCU7e9MzvdzpC2bPBlRGsfjwFoDGNYZW 79AtezM+ZXO4LOliofsOI3h5w4vnxyvLIZr4p3YT5Ik4oJmQWA4WQlu0a7QZ9fldnUjp TCY7j8xM25hn9csy7YN7A8HvcDaV3EMVMYHScSGI5Ckx8Jf5KKQ/RwKlEKRRO9B9+hpq q5KBrMacNgwwHPKdwbcWaiPo9M7oKo/qQ3T48d4MXY/3pT5G8uPYPk5mlBtYxtafwFr+ X7Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oxQKWJfMcrJ6vm0tvEa1wVhFRh9DrseAbumDA9b25Nk=; b=aEj4CHNa39KXG6gRgwd5DofKumhOuLxCuhvfQ2J3zTnu8pFmxUgJfMKpqCh3v7p/yJ pije6un0NU2reN2WL7EOMIe1dYci32LyWauJP9uyEWhnbHn3OpOTK3IozBMy8wEeg5UE THnCyDnKoZP/nRMf8lYZD4JG9BYiK+VI5UXcVz1h+LsZCd69H9HmLx419oYxtdyV/q9a CkGD1itNQD5cQ0rdY9GtEewTqyvvjL3ruuGo+A5kM2vonxGBu0oqPRs8V3er92let1TU PL0F7aVJge8q4k8PKnPH+XPifVCvZ3YXV2++/fXY5ue1IOUf+ZiFPibyqV6tzdQ4/v3b Q8Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa31-20020a170907869f00b007aaf5a45f5asi1542268ejc.47.2022.11.17.13.18.17; Thu, 17 Nov 2022 13:18:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240822AbiKQVMY (ORCPT + 99 others); Thu, 17 Nov 2022 16:12:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240743AbiKQVL5 (ORCPT ); Thu, 17 Nov 2022 16:11:57 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10BE06150F for ; Thu, 17 Nov 2022 13:11:57 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovmAq-0007P1-Gt; Thu, 17 Nov 2022 22:11:52 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ovmAo-004v5t-Un; Thu, 17 Nov 2022 22:11:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ovmAo-00HN0L-RH; Thu, 17 Nov 2022 22:11:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 3/4] pwm: Mark free pwm IDs as used in alloc_pwms() Date: Thu, 17 Nov 2022 22:11:42 +0100 Message-Id: <20221117211143.3817381-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> References: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1158; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=ZlStsEzR95pbO/ZmKK1BH2TWL3+UitzetoByqrewymQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBjdqOFnLAl+llZa8VfE8hGENgCr2OBorW+EwWwj6Sc hxVKKIWJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY3ajhQAKCRDB/BR4rcrsCQvECA CODszKvUNGCAramGpOaGYzlu1hv/odKmef2JzgxlizzQv+z1poDO3IeRXSiuE7ybsHKdBuZvDVbQcY 1xGQQefeaKCttbIHkgWK6IICO/9tAGFpXAR94Ib5V6lJtD/KuDiq8slejxKqM7hsg4cp2zbdOd0Lh5 +bb/PFYPrZqdzjpgDNux7hnMXaoqSQqXTPWU349JUOul1vS3/NFdmzbp3s17/5kI8U+8jqWzOGQ9cO H1msrkwSlSspKerk+msMJKtsWsd/BDa/mH48HsXwy3+6b/S8stWqfNW08FohfLc2dsAOEyDOB1sqSA uT43cx+lM3hdfI+guzKUQrYK4Zq4Pm X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749779666826760805?= X-GMAIL-MSGID: =?utf-8?q?1749779666826760805?= alloc_pwms() only identified a free range of IDs and this range was marked as used only later by pwmchip_add(). Instead let alloc_pwms() already do the marking (which makes the function actually allocating the range and so justifies the function name). This way access to the allocated_pwms bitfield is limited to two functions only. Reviewed-by: Andy Shevchenko Signed-off-by: Uwe Kleine-König --- drivers/pwm/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 2338119a09d8..b43b24bd3c9f 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -51,6 +51,8 @@ static int alloc_pwms(unsigned int count) if (start + count > MAX_PWMS) return -ENOSPC; + bitmap_set(allocated_pwms, start, count); + return start; } @@ -297,8 +299,6 @@ int pwmchip_add(struct pwm_chip *chip) radix_tree_insert(&pwm_tree, pwm->pwm, pwm); } - bitmap_set(allocated_pwms, chip->base, chip->npwm); - INIT_LIST_HEAD(&chip->list); list_add(&chip->list, &pwm_chips); From patchwork Thu Nov 17 21:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 21922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp626593wrr; Thu, 17 Nov 2022 13:17:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Aj9XYjIK8o1Og6gQZe/wVRw+NkvwJuyGf3yMzSsCRNbq5M1zETL/I+xHySE/KN5D7k/NC X-Received: by 2002:a05:6402:100b:b0:461:f1c6:1f22 with SMTP id c11-20020a056402100b00b00461f1c61f22mr3889249edu.95.1668719823348; Thu, 17 Nov 2022 13:17:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668719823; cv=none; d=google.com; s=arc-20160816; b=JXkXCH+zoPlwLNZiQr8JvXkBLWF5q3tactgddrf5IC9nYNLDv1DswY+BCiqdWedD/u lcU5DRI3NhAhoEeZ/vYF6QCPhw30A1waxhJrTFHsZvndHfGU4Q4trS+/4hq9DkpsfeZN Zt7arWhFhVT0kJclPGiwJEu3Xvh6sERWKlXFmQ0taDNbbMbZ1Ppd+dFLKGcG7cg0RO5o t3SosJQ2373Bq3pCNjBCaYVn+nA4ugiz55ZSrl7eRLVrEhxgIz+MVUq3kmPqlBJmL5IT 3ro96E1rTdmycb/SdowBoLbzyOhYrzJXIQYjN7cfC9bgU6JFkHs3rlNsIE0OuLge0Cf/ Y3/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lwegRYWjDmdb60ik9cQHxaC5am8EwHXOgsJ7+w/WGtE=; b=eXQWfFYQgwftw/AYczAvQx5A7vM3F5L6VP79mDzgf1IwtBNcJF+Xmp82cn3aZGkFws eUJOPmUqG6WBGtAzk3mMOscvpw5PHIQJWDsdcnP8hZXel9s3cjfgYQqDzQkyDXoba0Fa VcgFvz/IXeHL1R8IoYqHatrwstHxDOzfneDfkooG4doa9q7QeAfU3DtlZDd34j9oG3og 0vlz9PneucmUd51AZFc1UTMYdNS0wtOJX/y1q425Nv5GekZyMtZ9MkmqhhHMbM0rbA5H 8RJkZx8yLoIsC/SWwBwhHYFhIOWphsEq4V7NJcqiC1xs2IaJQRVkZM49m0CC0AlrabRr xaqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a05640234d400b0045945eed10asi1951118edc.5.2022.11.17.13.16.28; Thu, 17 Nov 2022 13:17:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240810AbiKQVMU (ORCPT + 99 others); Thu, 17 Nov 2022 16:12:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240742AbiKQVL5 (ORCPT ); Thu, 17 Nov 2022 16:11:57 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080CD61505 for ; Thu, 17 Nov 2022 13:11:57 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ovmAq-0007PE-MB; Thu, 17 Nov 2022 22:11:52 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ovmAp-004v5y-5E; Thu, 17 Nov 2022 22:11:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ovmAp-00HN0P-3H; Thu, 17 Nov 2022 22:11:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 4/4] pwm: Don't initialize list head before calling list_add() Date: Thu, 17 Nov 2022 22:11:43 +0100 Message-Id: <20221117211143.3817381-5-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> References: <20221117211143.3817381-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=754; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=K9jS1ZpU4xG3DAU/vPGftlodsO7fioNr3gh5KvNrnro=; b=owGbwMvMwMV48I9IxdpTbzgZT6slMSSXLe7M+hkc9qOvk/3InQeV8Sbtn0wv7nQSmCmkdkzfo3jR 2T19nYzGLAyMXAyyYoosdUVaYhMk1vy3K1nCDTOIlQlkCgMXpwBMJKyQg6HNZY6umEDMrI1ar2YY3H 5/6rjQrqpd845qHl8lp8bzyHhJYXpAWb+bfGez/vup2RetS1Q/fZ+QO71lqRZ/40aXt7lbtKqqbyb+ XbHS6Nfqn/vXW278w7NHQWrheS61yshil7jAvytu5Pv3H1M8NN3wpmpOYr1zzNX3X794bTHUOCEx5V iLUJHRamWja4uXWxRHGWzdziQVn3B12qtri7otDmkZtCxy2uAXe5w5XlRUe32h9ll9ebOvJj9T/rzz STviU5wh+mb6Yi6/+fy6Gn25VtWWnc37vP5F30ha2ldbdo7Bp5vz336jGuWIyyy5/Gp3zytUaRlmre 5dMj89Ro5JatrdTvHnpbGRaad5AQ== X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749779557075327045?= X-GMAIL-MSGID: =?utf-8?q?1749779557075327045?= list_add() just overwrites the members of the element to add (here: chip->list) without any checks, even in the DEBUG_LIST case. So save the effort to initialize the list. Reviewed-by: Andy Shevchenko Signed-off-by: Uwe Kleine-König --- drivers/pwm/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index b43b24bd3c9f..61bacd8d9b44 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -299,7 +299,6 @@ int pwmchip_add(struct pwm_chip *chip) radix_tree_insert(&pwm_tree, pwm->pwm, pwm); } - INIT_LIST_HEAD(&chip->list); list_add(&chip->list, &pwm_chips); mutex_unlock(&pwm_lock);