From patchwork Wed Dec 29 15:44:19 2021 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: 12701008 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CA54C433F5 for ; Wed, 29 Dec 2021 15:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240637AbhL2Po7 (ORCPT ); Wed, 29 Dec 2021 10:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240607AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 8A3FEC061756 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qK-8e; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8D-007KGh-Tm; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8C-00011q-8L; Wed, 29 Dec 2021 16:44:48 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 01/23] counter: Use container_of instead of drvdata to track counter_device Date: Wed, 29 Dec 2021 16:44:19 +0100 Message-Id: <20211229154441.38045-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1396; h=from:subject; bh=g5AkavRPc9KasQPrhOwNqTslienH33kFzd0pJErlhlU=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIQSLFOJ/a/KGmVNCh/amQvSqREydHIQgQrU5Zf 7izYy/SJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCEAAKCRDB/BR4rcrsCcmCB/ 9Ul1LyNCJzuJh1N891ue1F1mKn/GbQ7g1z9/4Ntnf6SJ9nE16vS2ZdsKef4pcueM5CIf9WbnM6ht/R Q/AmYb5mhYdjWSa0e0sHWSYC6hpiveHaj3bkthaAeYy4U8Fiut/wJaRaauuo9RlPITQOqDUwVcGMgt zmjqrXYWlKmbemowvWu4+aQeH153fRsF04iyI8VWkiqqMGKaFr1IkbyDt2uhQABzbgzVknBoIqdGHR tPw9uljdAklBwp53ektD3xDl2jL/iAKuzx/bABZBKdPdzP8/LZkEg4QlHnf0DcJGtrJ6lHIpZI816y DobbHiascSdouKjqeMFPzITYEXZP7M 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The counter core uses drvdata to find a struct counter_device from a struct device. However as the device is a member of struct counter_device, the lookup can be done faster (and a bit type safe) using container_of. There are no other users of drvdata, so the call to dev_set_drvdata can go away, too. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/counter-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c index 5acc54539623..f053a43c6c04 100644 --- a/drivers/counter/counter-core.c +++ b/drivers/counter/counter-core.c @@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida); static void counter_device_release(struct device *dev) { - struct counter_device *const counter = dev_get_drvdata(dev); + struct counter_device *const counter = + container_of(dev, struct counter_device, dev); counter_chrdev_remove(counter); ida_free(&counter_ida, dev->id); @@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter) dev->of_node = counter->parent->of_node; } device_initialize(dev); - dev_set_drvdata(dev, counter); err = counter_sysfs_add(counter); if (err < 0) From patchwork Wed Dec 29 15:44:20 2021 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: 12701004 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B62ABC433F5 for ; Wed, 29 Dec 2021 15:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240601AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240600AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 5D710C06173F for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qJ-8c; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8D-007KGk-OG; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8C-00011t-EV; Wed, 29 Dec 2021 16:44:48 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Patrick Havelange Subject: [PATCH v3 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata() Date: Wed, 29 Dec 2021 16:44:20 +0100 Message-Id: <20211229154441.38045-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=833; h=from:subject; bh=/yCYOFOf35wKxs8wO4zen2WYVkqvjzWqLvrPX8un9iM=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIUyKXjcXkcfU1V9GBs9o3gWt2oo6Gori/QX5tI N898cNmJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCFAAKCRDB/BR4rcrsCQ1kCA CArJG2MQRSte6giZnJdGCXopxwdzAN1HF1hAFA8HMD8kQbMb7L4Z8ipOEiA6aw24lsOWns8YLCIXXw ADV9/Wbsc3beEmv9gHXR+MAnycpHGnRlwh2vRYTHw7I4BTgJQy7CTsTCCaOAwFnoT+siKMwjM3iGzU NITTdEdSSjMyO1Y1v3Qdl7cu1n3r2jiG1SqwyCKYKZNg2LmoImqBUEgzs1DtiXizIFs2Oy34gKeqPc JWywS230K9rD6eL3SvoKqEs1WXDsCGa+UfbCcSYC/P9lvC+tYXKwjyYvHxVRy1zmVcQlJ0DVRxtly+ zkitvtNuT5PrQm8X1Lonf+kznApRkG 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The driver doesn't ever use platform_get_drvdata, so drop this unused call. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/ftm-quaddec.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index 5ef0478709cd..9272f7b58beb 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -269,8 +269,6 @@ static int ftm_quaddec_probe(struct platform_device *pdev) if (!ftm) return -ENOMEM; - platform_set_drvdata(pdev, ftm); - io = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!io) { dev_err(&pdev->dev, "Failed to get memory region\n"); From patchwork Wed Dec 29 15:44:21 2021 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: 12701022 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D61CC433EF for ; Wed, 29 Dec 2021 15:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240607AbhL2Po7 (ORCPT ); Wed, 29 Dec 2021 10:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240605AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 7C8D3C061748 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qI-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8D-007KGl-JT; Wed, 29 Dec 2021 16:44:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8C-00012J-Kj; Wed, 29 Dec 2021 16:44:48 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Kamel Bouhara Subject: [PATCH v3 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata() Date: Wed, 29 Dec 2021 16:44:21 +0100 Message-Id: <20211229154441.38045-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=861; h=from:subject; bh=p8o8yROvlaWuN65D0M/ICHbvt+4EVEiwwzlgD5lBUF4=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIXtICPBJku7BznPEoouEXs97mwzEf5mCrgFmTb 63gwHECJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCFwAKCRDB/BR4rcrsCcrjB/ 9Dzdj1rEu5B3Dly6IZL73FTaItDICYQ3thimMlmM2+3NnL6Tu2tYMRrBpSUtcQwKYg/YH3DQd4F+18 Xu7c5HVNgFZ9NRSdFROakcTRN/OpcFDBeG3Hzq8e+fX7lDEXwnEkY6WWjf/JrD/7XnUQJP1O9YKyau FKG8Lp+vAifGfWvWy3TV41Lsh7w4Kd9LuWAUa4OnbhcKxmqjDeu/w5qNx3E6yqd2qCwEyH7RFWwP2f y+og9va9eIzfwoYZO5LXJb1dAxC/4UdR1gOLpoGm3gx6yiePAMnSSCGm/UzX8KjruZ+0PRQe1zcOC+ +APCZU1QX/DlqZs6ZL9WPg33ABjkWv 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The driver doesn't ever use platform_get_drvdata, so drop this unused call. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/microchip-tcb-capture.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 0ab1b2716784..bb69f2e0ba93 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; - platform_set_drvdata(pdev, priv); - match = of_match_node(atmel_tc_of_match, np->parent); tcb_config = match->data; if (!tcb_config) { From patchwork Wed Dec 29 15:44:22 2021 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: 12701002 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E73AC4321E for ; Wed, 29 Dec 2021 15:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240634AbhL2Po6 (ORCPT ); Wed, 29 Dec 2021 10:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240606AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 7CB7EC061751 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qM-8e; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KGm-92; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8C-00012M-Pd; Wed, 29 Dec 2021 16:44:48 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 04/23] counter: Provide a wrapper to access device private data Date: Wed, 29 Dec 2021 16:44:22 +0100 Message-Id: <20211229154441.38045-5-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1735; h=from:subject; bh=nI58JSBfZvVnyN7QPFK4oMMervOf4JOAenELBrn+YQs=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIbL+kTmyWBIbdKKa2s0P6eY0bwWeRn4wqcnwKh wCF4VFGJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCGwAKCRDB/BR4rcrsCZ6nB/ wPbHt7Ab+jh/3Wi5VhpJW8ISfS+JNBiyGm6NzNFTIXfVyYHrwxK8ghQmZ5fw6Z/mvL4biwGtUbRvXz AZmO7y/OGhvOd7bodovcaKyOtr9nlXMbEJUTb4GrLsj/d9bruD9tgM68LGEmxUmY1tdwr232jnCW+Q wJaEssqIre5sOrQolxxFjJL7jZhkDBkk7J/DT7eRq3meMwvn6tnYl03+9GeyOv4F1e/lmpKtk+pUO0 kNP36EevieDJxbD8tl+W3qUEEuNqSk7CaC4y+iLqlxhSkBL4tvBfRF+AIsC1ep/U/ldKHQJVNsCLWL jYjgFmHxZwjxMK2r77Iw1kUoLN2hMv 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org For now this just wraps accessing struct counter_device::priv. However this is about to change and converting drivers to this helper individually makes fixing device lifetime issues result in easier to review patches. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/counter-core.c | 12 ++++++++++++ include/linux/counter.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c index f053a43c6c04..00c41f28c101 100644 --- a/drivers/counter/counter-core.c +++ b/drivers/counter/counter-core.c @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = { static dev_t counter_devt; +/** + * counter_priv - access counter device private data + * @counter: counter device + * + * Get the counter device private data + */ +void *counter_priv(const struct counter_device *const counter) +{ + return counter->priv; +} +EXPORT_SYMBOL_GPL(counter_priv); + /** * counter_register - register Counter to the system * @counter: pointer to Counter to register diff --git a/include/linux/counter.h b/include/linux/counter.h index b7d0a00a61cf..8daaa38c71d8 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -329,6 +329,8 @@ struct counter_device { struct mutex ops_exist_lock; }; +void *counter_priv(const struct counter_device *const counter); + int counter_register(struct counter_device *const counter); void counter_unregister(struct counter_device *const counter); int devm_counter_register(struct device *dev, From patchwork Wed Dec 29 15:44:23 2021 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: 12701006 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72E28C43217 for ; Wed, 29 Dec 2021 15:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240603AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240602AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 4436CC061574 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qN-8e; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KGp-9H; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-00012X-0F; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Syed Nayyar Waris Subject: [PATCH v3 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:23 +0100 Message-Id: <20211229154441.38045-6-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11509; h=from:subject; bh=m5kelU0DOWdEQwRdk8ZA3Vb77Tq8NFPRDRNC7MUJWPY=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIfk4uPcWzzd7B0Rai6Il3CSLNfmmKTphKZUS7R UKxFPA+JATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCHwAKCRDB/BR4rcrsCRP3B/ 4nT8Yp4uoXO5+aYo7xX/tSXkhKw0R0IAK06DFZT7CfrJA/w59OzcRjVD0p9A3aVZWZn/rVaaglxbhh G/GoC+6T2toanvUXCtf4eIiytT6B7TvJzqJKhQ6b7EDhwpFQTRsXajXDEVNnDqlIAerKsUnLsa4uIT z0jEXr5gOlBhvS6UDWYsEplWyzrujqbTeS7L6ZNwtL3Hg3TuUVvSV9cOJJTVVoPSchPE9svLEkCShc p3RL9a8cf8IgOyqQxN6zGHfBFCZS/nmafrC4yZibLsmo6m5g7gUMcv/dub4BMg02Sti5NWPXilK4M7 Y0NmO0JMtoASF8diFytLaKclhzYMCa 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/104-quad-8.c | 58 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 1cbd60aaed69..6e5286cd1d4e 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -113,7 +113,7 @@ static int quad8_signal_read(struct counter_device *counter, struct counter_signal *signal, enum counter_signal_level *level) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); unsigned int state; /* Only Index signal levels can be read */ @@ -131,7 +131,7 @@ static int quad8_signal_read(struct counter_device *counter, static int quad8_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int base_offset = priv->base + 2 * count->id; unsigned int flags; unsigned int borrow; @@ -163,7 +163,7 @@ static int quad8_count_read(struct counter_device *counter, static int quad8_count_write(struct counter_device *counter, struct counter_count *count, u64 val) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int base_offset = priv->base + 2 * count->id; unsigned long irqflags; int i; @@ -213,7 +213,7 @@ static int quad8_function_read(struct counter_device *counter, struct counter_count *count, enum counter_function *function) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int id = count->id; unsigned long irqflags; @@ -243,7 +243,7 @@ static int quad8_function_write(struct counter_device *counter, struct counter_count *count, enum counter_function function) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int id = count->id; unsigned int *const quadrature_mode = priv->quadrature_mode + id; unsigned int *const scale = priv->quadrature_scale + id; @@ -305,7 +305,7 @@ static int quad8_direction_read(struct counter_device *counter, struct counter_count *count, enum counter_count_direction *direction) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); unsigned int ud_flag; const unsigned int flag_addr = priv->base + 2 * count->id + 1; @@ -335,7 +335,7 @@ static int quad8_action_read(struct counter_device *counter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); int err; enum counter_function function; const size_t signal_a_id = count->synapses[0].signal->id; @@ -399,7 +399,7 @@ enum { static int quad8_events_configure(struct counter_device *counter) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); unsigned long irq_enabled = 0; unsigned long irqflags; size_t channel; @@ -442,7 +442,7 @@ static int quad8_events_configure(struct counter_device *counter) static int quad8_watch_validate(struct counter_device *counter, const struct counter_watch *watch) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); if (watch->channel > QUAD8_NUM_COUNTERS - 1) return -EINVAL; @@ -497,7 +497,7 @@ static int quad8_index_polarity_get(struct counter_device *counter, struct counter_signal *signal, u32 *index_polarity) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id - 16; *index_polarity = priv->index_polarity[channel_id]; @@ -509,7 +509,7 @@ static int quad8_index_polarity_set(struct counter_device *counter, struct counter_signal *signal, u32 index_polarity) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id - 16; const int base_offset = priv->base + 2 * channel_id + 1; unsigned long irqflags; @@ -538,7 +538,7 @@ static int quad8_synchronous_mode_get(struct counter_device *counter, struct counter_signal *signal, u32 *synchronous_mode) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id - 16; *synchronous_mode = priv->synchronous_mode[channel_id]; @@ -550,7 +550,7 @@ static int quad8_synchronous_mode_set(struct counter_device *counter, struct counter_signal *signal, u32 synchronous_mode) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id - 16; const int base_offset = priv->base + 2 * channel_id + 1; unsigned long irqflags; @@ -589,7 +589,7 @@ static int quad8_count_mode_read(struct counter_device *counter, struct counter_count *count, enum counter_count_mode *cnt_mode) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); /* Map 104-QUAD-8 count mode to Generic Counter count mode */ switch (priv->count_mode[count->id]) { @@ -614,7 +614,7 @@ static int quad8_count_mode_write(struct counter_device *counter, struct counter_count *count, enum counter_count_mode cnt_mode) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); unsigned int count_mode; unsigned int mode_cfg; const int base_offset = priv->base + 2 * count->id + 1; @@ -661,7 +661,7 @@ static int quad8_count_mode_write(struct counter_device *counter, static int quad8_count_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); *enable = priv->ab_enable[count->id]; @@ -671,7 +671,7 @@ static int quad8_count_enable_read(struct counter_device *counter, static int quad8_count_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int base_offset = priv->base + 2 * count->id; unsigned long irqflags; unsigned int ior_cfg; @@ -699,7 +699,7 @@ static const char *const quad8_noise_error_states[] = { static int quad8_error_noise_get(struct counter_device *counter, struct counter_count *count, u32 *noise_error) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); const int base_offset = priv->base + 2 * count->id + 1; *noise_error = !!(inb(base_offset) & QUAD8_FLAG_E); @@ -710,7 +710,7 @@ static int quad8_error_noise_get(struct counter_device *counter, static int quad8_count_preset_read(struct counter_device *counter, struct counter_count *count, u64 *preset) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); *preset = priv->preset[count->id]; @@ -736,7 +736,7 @@ static void quad8_preset_register_set(struct quad8 *const priv, const int id, static int quad8_count_preset_write(struct counter_device *counter, struct counter_count *count, u64 preset) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); unsigned long irqflags; /* Only 24-bit values are supported */ @@ -755,7 +755,7 @@ static int quad8_count_preset_write(struct counter_device *counter, static int quad8_count_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); unsigned long irqflags; spin_lock_irqsave(&priv->lock, irqflags); @@ -780,7 +780,7 @@ static int quad8_count_ceiling_read(struct counter_device *counter, static int quad8_count_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 ceiling) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); unsigned long irqflags; /* Only 24-bit values are supported */ @@ -807,7 +807,7 @@ static int quad8_count_preset_enable_read(struct counter_device *counter, struct counter_count *count, u8 *preset_enable) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); *preset_enable = !priv->preset_enable[count->id]; @@ -818,7 +818,7 @@ static int quad8_count_preset_enable_write(struct counter_device *counter, struct counter_count *count, u8 preset_enable) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const int base_offset = priv->base + 2 * count->id + 1; unsigned long irqflags; unsigned int ior_cfg; @@ -845,7 +845,7 @@ static int quad8_signal_cable_fault_read(struct counter_device *counter, struct counter_signal *signal, u8 *cable_fault) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id / 2; unsigned long irqflags; bool disabled; @@ -875,7 +875,7 @@ static int quad8_signal_cable_fault_enable_read(struct counter_device *counter, struct counter_signal *signal, u8 *enable) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id / 2; *enable = !!(priv->cable_fault_enable & BIT(channel_id)); @@ -887,7 +887,7 @@ static int quad8_signal_cable_fault_enable_write(struct counter_device *counter, struct counter_signal *signal, u8 enable) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id / 2; unsigned long irqflags; unsigned int cable_fault_enable; @@ -913,7 +913,7 @@ static int quad8_signal_fck_prescaler_read(struct counter_device *counter, struct counter_signal *signal, u8 *prescaler) { - const struct quad8 *const priv = counter->priv; + const struct quad8 *const priv = counter_priv(counter); *prescaler = priv->fck_prescaler[signal->id / 2]; @@ -924,7 +924,7 @@ static int quad8_signal_fck_prescaler_write(struct counter_device *counter, struct counter_signal *signal, u8 prescaler) { - struct quad8 *const priv = counter->priv; + struct quad8 *const priv = counter_priv(counter); const size_t channel_id = signal->id / 2; const int base_offset = priv->base + 2 * channel_id; unsigned long irqflags; From patchwork Wed Dec 29 15:44:24 2021 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: 12701011 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32F5DC433F5 for ; Wed, 29 Dec 2021 15:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240657AbhL2PpB (ORCPT ); Wed, 29 Dec 2021 10:45:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240610AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 955A4C061759 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qL-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KGt-6b; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-00012i-66; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Oleksij Rempel , Ahmad Fatoum Subject: [PATCH v3 06/23] counter: interrupt-cnt: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:24 +0100 Message-Id: <20211229154441.38045-7-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2386; h=from:subject; bh=ScSX9M6WEmr2zHotq+DCYxiwYwGU/fI0ZlDKzhLgR4A=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIivs4jX8wmoAm13sWLSZ0VrIbwBWnmCxW/ctwa JodCCm6JATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCIgAKCRDB/BR4rcrsCXvLCA CJFO0FCnL1082tN4fa69vbNcQmlh6eAdytJgc6d2hfSKhOUvFXRl9ZUYz4VAcqcfZncI0hD15/4Y1f VUInwYjW/p+dO/f+bp4CPNkCJJt3sRP1pp3twb7FdD2boe63C/XHBDmHCbr9jFPag0iZNwgxLqsyD4 JFx2RYHBiP/+/0TmrlirBTz4j73n2XVkk7uPWfWQSafFKUGmFEVimCHfKVwoQr4KF6WavTFAW4CKsy dEK9J7a7mKy93wSWVvYX/Idai9ffU2pLNmA/ONVPhWBvjcd0W5gWYo1gVD3Y+oFnKMmI4OViTcKOR5 XAyalRnLvmJduFEGYDPhjwaC1quVAj 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/interrupt-cnt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index 8514a87fcbee..4bf706ef46e2 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -37,7 +37,7 @@ static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id) static int interrupt_cnt_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct interrupt_cnt_priv *priv = counter->priv; + struct interrupt_cnt_priv *priv = counter_priv(counter); *enable = priv->enabled; @@ -47,7 +47,7 @@ static int interrupt_cnt_enable_read(struct counter_device *counter, static int interrupt_cnt_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct interrupt_cnt_priv *priv = counter->priv; + struct interrupt_cnt_priv *priv = counter_priv(counter); if (priv->enabled == enable) return 0; @@ -85,7 +85,7 @@ static int interrupt_cnt_action_read(struct counter_device *counter, static int interrupt_cnt_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct interrupt_cnt_priv *priv = counter->priv; + struct interrupt_cnt_priv *priv = counter_priv(counter); *val = atomic_read(&priv->count); @@ -95,7 +95,7 @@ static int interrupt_cnt_read(struct counter_device *counter, static int interrupt_cnt_write(struct counter_device *counter, struct counter_count *count, const u64 val) { - struct interrupt_cnt_priv *priv = counter->priv; + struct interrupt_cnt_priv *priv = counter_priv(counter); if (val != (typeof(priv->count.counter))val) return -ERANGE; @@ -122,7 +122,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter, struct counter_signal *signal, enum counter_signal_level *level) { - struct interrupt_cnt_priv *priv = counter->priv; + struct interrupt_cnt_priv *priv = counter_priv(counter); int ret; if (!priv->gpio) From patchwork Wed Dec 29 15:44:25 2021 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: 12701003 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FDABC4332F for ; Wed, 29 Dec 2021 15:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240600AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240603AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 6AFCEC061746 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qO-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KGv-BD; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-00012s-C3; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Kamel Bouhara Subject: [PATCH v3 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:25 +0100 Message-Id: <20211229154441.38045-8-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2839; h=from:subject; bh=g+9shAfdI+y9E4bonTCycgoVLFyAnN2LNJinmiWu6Z4=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIImvJA3uZ/zFjqlOacr59iSzBNt2Kus4WzOXJ0b vq6ynxOJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCJgAKCRDB/BR4rcrsCZjfB/ 49m3/C0ARKic8yteuHrcTtcA1Y+XIDFjuyTiKde0VQUVODqjQESWFRUOZvwXdIXlnSzXu5wV23pu8J 4v8nxapj2THiaLS4y0f3/8swLIWUhatOndqUDDA+cU00LoXIxnAoC3xwtGfsRyLjTAnN5LEyfPPCL7 mxsBa3wR3ZiEOyTHKKvajgPj0DZdhKSO7WC5wWPYevbiKgzKlCfNIMKupyvec6A1sz5y/R+UCHVNtw xmhRAVQN6GzMf6u/40f5gO7UzufrZE7LWLKkyB8bQ+Ydh+zGw6UhqK8ozDQ0UuVKiggCKECcGA7uH6 Aew6RBHusx6XLXpheBrtJx4HQh+uvA 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/microchip-tcb-capture.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index bb69f2e0ba93..1b56b7444668 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter, struct counter_count *count, enum counter_function *function) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); if (priv->qdec_mode) *function = COUNTER_FUNCTION_QUADRATURE_X4; @@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter, struct counter_count *count, enum counter_function function) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); u32 bmr, cmr; regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr); @@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter, struct counter_signal *signal, enum counter_signal_level *lvl) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); bool sigstatus; u32 sr; @@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); u32 cmr; regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); @@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter, struct counter_synapse *synapse, enum counter_synapse_action action) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); u32 edge = ATMEL_TC_ETRGEDG_NONE; /* QDEC mode is rising edge only */ @@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter, static int mchp_tc_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct mchp_tc_data *const priv = counter->priv; + struct mchp_tc_data *const priv = counter_priv(counter); u32 cnt; regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt); From patchwork Wed Dec 29 15:44:26 2021 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: 12701021 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A379FC433F5 for ; Wed, 29 Dec 2021 15:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240649AbhL2PpA (ORCPT ); Wed, 29 Dec 2021 10:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240612AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 A3B85C06173E for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qP-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KH0-Cu; Wed, 29 Dec 2021 16:44:49 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-000134-Ht; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jarkko Nikula Subject: [PATCH v3 08/23] counter: intel-qep: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:26 +0100 Message-Id: <20211229154441.38045-9-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3609; h=from:subject; bh=WXYWs++l/auzrMsm4SYpaBBUwt/mk3BB83mnuuKAoFc=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIpteClU9C+Sp77hONf86I9RnxTmYtFqPAcp+CW 1DTIrfSJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCKQAKCRDB/BR4rcrsCVqEB/ kBd9Bqf1JHrqj4mMipIGaE+/YNWRg0gQSJpIDgD7TC+nxR+p9Xj79Uf75YP4GpTv1EETBp0QIDGYSo wiz7SO+/w0lncP/MC/nbpGvML5nlxqBM1WHDtpezDBpovfCcdiTGfT529S2S0GNkI2SSO10ubQKRlz 7RShEa33Vwym7WUE5Hylm/GdzIPuKxcq6+C2ORueOxoxt0BSjoYgVWG0b4tWLIJy7SKEo9VjW8YAKl iD8PmoMVNFqXUqQiw0LLs4bA7ICfHM0P3G2JEolYXjKRU+gI3gu2Yx9V2TnXx7eGFXbTwsuOZSrH9k 4Z4ivvDXBCbvlAzMGieI2ixxxsx2zz 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König Acked-by: Jarkko Nikula --- drivers/counter/intel-qep.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 0924d16de6e2..8f84a48508ac 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -109,7 +109,7 @@ static void intel_qep_init(struct intel_qep *qep) static int intel_qep_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct intel_qep *const qep = counter->priv; + struct intel_qep *const qep = counter_priv(counter); pm_runtime_get_sync(qep->dev); *val = intel_qep_readl(qep, INTEL_QEPCOUNT); @@ -176,7 +176,7 @@ static struct counter_synapse intel_qep_count_synapses[] = { static int intel_qep_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); pm_runtime_get_sync(qep->dev); *ceiling = intel_qep_readl(qep, INTEL_QEPMAX); @@ -188,7 +188,7 @@ static int intel_qep_ceiling_read(struct counter_device *counter, static int intel_qep_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 max) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); int ret = 0; /* Intel QEP ceiling configuration only supports 32-bit values */ @@ -213,7 +213,7 @@ static int intel_qep_ceiling_write(struct counter_device *counter, static int intel_qep_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); *enable = qep->enabled; @@ -223,7 +223,7 @@ static int intel_qep_enable_read(struct counter_device *counter, static int intel_qep_enable_write(struct counter_device *counter, struct counter_count *count, u8 val) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); u32 reg; bool changed; @@ -256,7 +256,7 @@ static int intel_qep_spike_filter_ns_read(struct counter_device *counter, struct counter_count *count, u64 *length) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); u32 reg; pm_runtime_get_sync(qep->dev); @@ -277,7 +277,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter, struct counter_count *count, u64 length) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); u32 reg; bool enable; int ret = 0; @@ -326,7 +326,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter, struct counter_count *count, u8 *preset_enable) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); u32 reg; pm_runtime_get_sync(qep->dev); @@ -341,7 +341,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter, static int intel_qep_preset_enable_write(struct counter_device *counter, struct counter_count *count, u8 val) { - struct intel_qep *qep = counter->priv; + struct intel_qep *qep = counter_priv(counter); u32 reg; int ret = 0; From patchwork Wed Dec 29 15:44:27 2021 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: 12701005 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B92BCC43219 for ; Wed, 29 Dec 2021 15:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240602AbhL2Po6 (ORCPT ); Wed, 29 Dec 2021 10:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240604AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 741BDC061747 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qQ-8e; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KH7-Qe; Wed, 29 Dec 2021 16:44:50 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-00013X-OB; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Patrick Havelange Subject: [PATCH v3 09/23] counter: ftm-quaddec: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:27 +0100 Message-Id: <20211229154441.38045-10-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1951; h=from:subject; bh=CBgQ6yn9pj3aVonUUpdY82noKJTEGFd3OM3t7zq90/s=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIItbT6rcc1P8BZoC0eWIxD1oV+ZfaY7kIdK/vmy liV1RpmJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCLQAKCRDB/BR4rcrsCbUoCA CNvOVDtSfeW0cudvIpVteI31yLjT6T8PakcWUN3Tev54PdIPMIYwLap3qDEPk/ZrNbCJVP1TIM15yq NGi/La9bonRNw0Is7TNjuEft3Zj6XtnPGvzrRSi9cTiRIUZtHcd2GUhtGobnEO8TjWNN988+EETV28 0I1bx/6hUtDp8nXR+JfBxcFM8WONY3TPJL1DUEoC6+/6U0+RxH5QAzulNNhrnVCFSFcAziiNiyZqSB RXfnzv2AFOEkh+1v+FVib7MAc7tphryiTz7k7Qb7mZZMRahSrsRoBuCbWJBbEWFcN7A8Xoxa4O11yf uXDJ4NLVC32a6ULRBeG0W4iwmCbxJs 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/ftm-quaddec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index 9272f7b58beb..f5d92df6a611 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -118,7 +118,7 @@ static void ftm_quaddec_disable(void *ftm) static int ftm_quaddec_get_prescaler(struct counter_device *counter, struct counter_count *count, u32 *cnt_mode) { - struct ftm_quaddec *ftm = counter->priv; + struct ftm_quaddec *ftm = counter_priv(counter); uint32_t scflags; ftm_read(ftm, FTM_SC, &scflags); @@ -131,7 +131,7 @@ static int ftm_quaddec_get_prescaler(struct counter_device *counter, static int ftm_quaddec_set_prescaler(struct counter_device *counter, struct counter_count *count, u32 cnt_mode) { - struct ftm_quaddec *ftm = counter->priv; + struct ftm_quaddec *ftm = counter_priv(counter); mutex_lock(&ftm->ftm_quaddec_mutex); @@ -162,7 +162,7 @@ static int ftm_quaddec_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct ftm_quaddec *const ftm = counter->priv; + struct ftm_quaddec *const ftm = counter_priv(counter); uint32_t cntval; ftm_read(ftm, FTM_CNT, &cntval); @@ -176,7 +176,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter, struct counter_count *count, const u64 val) { - struct ftm_quaddec *const ftm = counter->priv; + struct ftm_quaddec *const ftm = counter_priv(counter); if (val != 0) { dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n"); From patchwork Wed Dec 29 15:44:28 2021 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: 12701014 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A8BC433FE for ; Wed, 29 Dec 2021 15:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240698AbhL2PpG (ORCPT ); Wed, 29 Dec 2021 10:45:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240644AbhL2PpA (ORCPT ); Wed, 29 Dec 2021 10:45:00 -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 D3D33C061574 for ; Wed, 29 Dec 2021 07:44:59 -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 1n2b8J-0006qR-U0; Wed, 29 Dec 2021 16:44:55 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8E-007KH8-Sq; Wed, 29 Dec 2021 16:44:50 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8D-00013i-U1; Wed, 29 Dec 2021 16:44:49 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, David Lechner Subject: [PATCH v3 10/23] counter: ti-eqep: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:28 +0100 Message-Id: <20211229154441.38045-11-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=722; h=from:subject; bh=UH/1V9o9IsEhvPOBCAdcab4TG315ms1cIGl6e2AcYsU=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIIx3PbpyxDVpf4se5t5cLwiZFWobaV9D5VZuTEi ZPez8RyJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCMQAKCRDB/BR4rcrsCSZmB/ sHwyyqIMwjXnAr5m/XLSsip8eGKguB+u4QI+LlJeS1UqkTvXwjbwTol8fmi5KOYP0cxmxoOpfnjBWV x/1XPl9nMrdvZhA7CDyJpqRqGzMGANB0d17KbtMvnxQBinK/9TT2/mGR0JXc4HY7p3DvUmy2aeQ73U JlWVkhUT+uPq+wob/QIv1+aRv/gpNENvBOsvBZ2eTk8yEeGURNaEivb0N78ix85f93sDqC4XjjX0jX /ISYdV3FOrzvtp4QrV35g9vU4OaFrvNH0G4xdd9ZwyMh0cJQa8UEJOWxm0gpcDBJvIBFTuR9/ZYZZi pr32E6V/lBv/s/VMpnrmkhUJ2CsC/d 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Signed-off-by: Uwe Kleine-König Acked-by: William Breathitt Gray Acked-by: David Lechner --- drivers/counter/ti-eqep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index 9e0e46bca4c2..2c70b900a6cf 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -89,7 +89,7 @@ struct ti_eqep_cnt { static struct ti_eqep_cnt *ti_eqep_count_from_counter(struct counter_device *counter) { - return container_of(counter, struct ti_eqep_cnt, counter); + return counter_priv(counter); } static int ti_eqep_count_read(struct counter_device *counter, From patchwork Wed Dec 29 15:44:29 2021 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: 12701016 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 241B3C4332F for ; Wed, 29 Dec 2021 15:45:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240621AbhL2PpI (ORCPT ); Wed, 29 Dec 2021 10:45:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240679AbhL2PpD (ORCPT ); Wed, 29 Dec 2021 10:45:03 -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 A69B0C061746 for ; Wed, 29 Dec 2021 07:45:02 -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 1n2b8N-0006qS-53; Wed, 29 Dec 2021 16:44:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8F-007KHA-79; Wed, 29 Dec 2021 16:44:50 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8E-00013l-3P; Wed, 29 Dec 2021 16:44:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:29 +0100 Message-Id: <20211229154441.38045-12-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3728; h=from:subject; bh=HzpiF2hM7TUPP6R0Q8sjl1mleB8WWDqnHZa5zXo9C1Q=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzII0MowiChMBSWxMR+GhqtTMOuc77XHdTRdcTAEG HfEiyxCJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCNAAKCRDB/BR4rcrsCT6+B/ 9xWxx34MaOKTo9FI0IkyVwKJh7mHvniZZQenne8PJ7EumDe+20Qv2lWFbp74ItJcRF0Oow06zAK3hv mSvJ2BdKY+tknwZ0t2lPArowgILMzuEb+UPHwJsqhssiQGmjfu9lPcNCpUUkYYq2gd/38bz3XngFuK 8VY+fcW8UY3EeTbMe7bXNFp10tULsBFMUHnbejsn0EOVN2uk7udY51Qy3aYsPk5PtrGm1jki6b5JDm 15Zx5urFRfytMProdH29FBcddo01ettSn50rKhKJr9vIhoFKE1C/QgS+m0ZzDPBDSw8FL0dg24LkV+ i4DN3P1fmxLgGx6XZwJatxaL7MroO+ 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index 5168833b1fdf..9cf00e929cc0 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = { static int stm32_lptim_cnt_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); u32 cnt; int ret; @@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter, struct counter_count *count, enum counter_function *function) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); if (!priv->quadrature_mode) { *function = COUNTER_FUNCTION_INCREASE; @@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter, struct counter_count *count, enum counter_function function) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); if (stm32_lptim_is_enabled(priv)) return -EBUSY; @@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); int ret; ret = stm32_lptim_is_enabled(priv); @@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); int ret; /* Check nobody uses the timer, or already disabled/enabled */ @@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); *ceiling = priv->ceiling; @@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 ceiling) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); if (stm32_lptim_is_enabled(priv)) return -EBUSY; @@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); enum counter_function function; int err; @@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter, struct counter_synapse *synapse, enum counter_synapse_action action) { - struct stm32_lptim_cnt *const priv = counter->priv; + struct stm32_lptim_cnt *const priv = counter_priv(counter); enum counter_function function; int err; From patchwork Wed Dec 29 15:44:30 2021 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: 12701020 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC373C433F5 for ; Wed, 29 Dec 2021 15:45:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240712AbhL2PpK (ORCPT ); Wed, 29 Dec 2021 10:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240674AbhL2PpC (ORCPT ); Wed, 29 Dec 2021 10:45:02 -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 705A1C061401 for ; Wed, 29 Dec 2021 07:45:02 -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 1n2b8N-0006qT-51; Wed, 29 Dec 2021 16:44:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8F-007KHE-Bs; Wed, 29 Dec 2021 16:44:50 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8E-000144-AW; Wed, 29 Dec 2021 16:44:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper Date: Wed, 29 Dec 2021 16:44:30 +0100 Message-Id: <20211229154441.38045-13-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3961; h=from:subject; bh=wdtKkluXMmzSj2wb5mCtiu7A85AS1CCPgxJ//4kVhbg=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzII43kwwwRodcPX7bEvfoLeNLmWXzuuZZVvYByRe IiHkw0WJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCOAAKCRDB/BR4rcrsCbfvB/ 9GYkY5IfFHlZ8gE7GGmUcvU0cAHhCxX2T9XS59eBp3yO1/c4PMubdMIqYHrCOKyEm2SqIoyMqCc/9e cAOQRc1tyoP0hY57o4/pqdVHDMXPQg9MM8XaYUbupf6MVg8AhXd1VJUn6l5gRz4ijT0hFFg6n/9/qX NRTvE+XDCroKRJFBg88oCzfX3agNnvVKTEE6pYQl/Lvo82Um8gvlLCCr1jHjoIGv41r3qy7JUv9BEO tBt4qenVtPXcHRQZPo4VuFElSvjy75J8jEvENRYVbDWt7OUH5a9UvBUlDlTIvzs62Zhll6aeZDRbUQ gjxxrxCtGWa/hM6OtAD/VARE+4qBxv 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a straight forward conversion to the new counter_priv() wrapper. Acked-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/stm32-timer-cnt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 0546e932db0c..4b05b198a8d8 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = { static int stm32_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cnt; regmap_read(priv->regmap, TIM_CNT, &cnt); @@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter, static int stm32_count_write(struct counter_device *counter, struct counter_count *count, const u64 val) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 ceiling; regmap_read(priv->regmap, TIM_ARR, &ceiling); @@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter, struct counter_count *count, enum counter_function *function) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 smcr; regmap_read(priv->regmap, TIM_SMCR, &smcr); @@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter, struct counter_count *count, enum counter_function function) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cr1, sms; switch (function) { @@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter, struct counter_count *count, enum counter_count_direction *direction) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cr1; regmap_read(priv->regmap, TIM_CR1, &cr1); @@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter, static int stm32_count_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 arr; regmap_read(priv->regmap, TIM_ARR, &arr); @@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter, static int stm32_count_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 ceiling) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); if (ceiling > priv->max_arr) return -ERANGE; @@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter, static int stm32_count_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cr1; regmap_read(priv->regmap, TIM_CR1, &cr1); @@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter, static int stm32_count_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct stm32_timer_cnt *const priv = counter->priv; + struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cr1; if (enable) { From patchwork Wed Dec 29 15:44:31 2021 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: 12701010 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DB09C433FE for ; Wed, 29 Dec 2021 15:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240664AbhL2PpB (ORCPT ); Wed, 29 Dec 2021 10:45:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240591AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44: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 A884AC06175B for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qV-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHH-1l; Wed, 29 Dec 2021 16:44:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8E-000147-Jy; Wed, 29 Dec 2021 16:44:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 13/23] counter: Provide alternative counter registration functions Date: Wed, 29 Dec 2021 16:44:31 +0100 Message-Id: <20211229154441.38045-14-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8441; h=from:subject; bh=LoJduvOk/cZiF0CTIEbFpZdJ1yfErUzWTdox/VibSl0=; b=owGbwMvMwMV48I9IxdpTbzgZT6slMSSeabKR1YsR/pXS/3DJ9CDfLQtC5XsuFOZ+M29+9d3z1n6h ogS9TkZjFgZGLgZZMUWWuiItsQkSa/7blSzhhhnEygQyhYGLUwAm8oqd/Q/HYkEep956SW3W48c4BO dPyTjt0dde5bf8b3bz9wuCfxUDZr6Y8oPfYV523oop3ws/1spJ972NuyTHLCCVo1RmX+mnVnXURUZe fI3lC7GSo78e6EXt8boqFMS8QnTLdO+giACHStWIfoZs0bwGodq+WQ+UAqbMSbt96XHj7fg6z38pl8 VsVLOKDGWmB259+TvxtbfWvDdXn6XYSB+6NvNh3OZ3l7mLw7rubGyesy2hLuy9C/OELfYyCxc+/ci9 0qzVnMNmoZb2z19z9tkYR1/Va55TuZb5Hqd4vulzY1XOhbxlG0W3Kar8WH/d7NuiaMNq/xXRtmt6Ei dOldStCFH5fGbbvl5O37KSl5u6AQ== 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The current implementation gets device lifetime tracking wrong. The problem is that allocation of struct counter_device is controlled by the individual drivers but this structure contains a struct device that might have to live longer than a driver is bound. As a result a command sequence like: { sleep 5; echo bang; } > /dev/counter0 & sleep 1; echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind can keep a reference to the struct device and unbinding results in freeing the memory occupied by this device resulting in an oops. This commit provides two new functions (plus some helpers): - counter_alloc() to allocate a struct counter_device that is automatically freed once the embedded struct device is released - counter_add() to register such a device. Note that this commit doesn't fix any issues, all drivers have to be converted to these new functions to correct the lifetime problems. Signed-off-by: Uwe Kleine-König Reviewed-by: Jonathan Cameron --- drivers/counter/counter-core.c | 168 ++++++++++++++++++++++++++++++++- include/linux/counter.h | 15 +++ 2 files changed, 181 insertions(+), 2 deletions(-) diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c index 00c41f28c101..b3fa15bbcbdb 100644 --- a/drivers/counter/counter-core.c +++ b/drivers/counter/counter-core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -24,6 +25,16 @@ /* Provides a unique ID for each counter device */ static DEFINE_IDA(counter_ida); +struct counter_device_allochelper { + struct counter_device counter; + + /* + * This is cache line aligned to ensure private data behaves like if it + * were kmalloced separately. + */ + unsigned long privdata[] ____cacheline_aligned; +}; + static void counter_device_release(struct device *dev) { struct counter_device *const counter = @@ -31,6 +42,9 @@ static void counter_device_release(struct device *dev) counter_chrdev_remove(counter); ida_free(&counter_ida, dev->id); + + if (!counter->legacy_device) + kfree(container_of(counter, struct counter_device_allochelper, counter)); } static struct device_type counter_device_type = { @@ -53,7 +67,14 @@ static dev_t counter_devt; */ void *counter_priv(const struct counter_device *const counter) { - return counter->priv; + if (counter->legacy_device) { + return counter->priv; + } else { + struct counter_device_allochelper *ch = + container_of(counter, struct counter_device_allochelper, counter); + + return &ch->privdata; + } } EXPORT_SYMBOL_GPL(counter_priv); @@ -74,6 +95,8 @@ int counter_register(struct counter_device *const counter) int id; int err; + counter->legacy_device = true; + /* Acquire unique ID */ id = ida_alloc(&counter_ida, GFP_KERNEL); if (id < 0) @@ -114,6 +137,95 @@ int counter_register(struct counter_device *const counter) } EXPORT_SYMBOL_GPL(counter_register); +/** + * counter_alloc - allocate a counter_device + * @sizeof_priv: size of the driver private data + * + * This is part one of counter registration. The structure is allocated + * dynamically to ensure the right lifetime for the embedded struct device. + * + * If this succeeds, call counter_put() to get rid of the counter_device again. + */ +struct counter_device *counter_alloc(size_t sizeof_priv) +{ + struct counter_device_allochelper *ch; + struct counter_device *counter; + struct device *dev; + int err; + + ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL); + if (!ch) { + err = -ENOMEM; + goto err_alloc_ch; + } + + counter = &ch->counter; + dev = &counter->dev; + + /* Acquire unique ID */ + err = ida_alloc(&counter_ida, GFP_KERNEL); + if (err < 0) + goto err_ida_alloc; + dev->id = err; + + mutex_init(&counter->ops_exist_lock); + dev->type = &counter_device_type; + dev->bus = &counter_bus_type; + dev->devt = MKDEV(MAJOR(counter_devt), dev->id); + + err = counter_chrdev_add(counter); + if (err < 0) + goto err_chrdev_add; + + device_initialize(dev); + + return counter; + +err_chrdev_add: + + ida_free(&counter_ida, dev->id); +err_ida_alloc: + + kfree(ch); +err_alloc_ch: + + return ERR_PTR(err); +} +EXPORT_SYMBOL_GPL(counter_alloc); + +void counter_put(struct counter_device *counter) +{ + put_device(&counter->dev); +} +EXPORT_SYMBOL_GPL(counter_put); + +/** + * counter_add - complete registration of a counter + * @counter: the counter to add + * + * This is part two of counter registration. + * + * If this succeeds, call counter_unregister() to get rid of the counter_device again. + */ +int counter_add(struct counter_device *counter) +{ + int err; + struct device *dev = &counter->dev; + + if (counter->parent) { + dev->parent = counter->parent; + dev->of_node = counter->parent->of_node; + } + + err = counter_sysfs_add(counter); + if (err < 0) + return err; + + /* implies device_add(dev) */ + return cdev_device_add(&counter->chrdev, dev); +} +EXPORT_SYMBOL_GPL(counter_add); + /** * counter_unregister - unregister Counter from the system * @counter: pointer to Counter to unregister @@ -134,7 +246,8 @@ void counter_unregister(struct counter_device *const counter) mutex_unlock(&counter->ops_exist_lock); - put_device(&counter->dev); + if (counter->legacy_device) + put_device(&counter->dev); } EXPORT_SYMBOL_GPL(counter_unregister); @@ -168,6 +281,57 @@ int devm_counter_register(struct device *dev, } EXPORT_SYMBOL_GPL(devm_counter_register); +static void devm_counter_put(void *counter) +{ + counter_put(counter); +} + +/** + * devm_counter_alloc - allocate a counter_device + * @dev: the device to register the release callback for + * @sizeof_priv: size of the driver private data + * + * This is the device managed version of counter_add(). It registers a cleanup + * callback to care for calling counter_put(). + */ +struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv) +{ + struct counter_device *counter; + int err; + + counter = counter_alloc(sizeof_priv); + if (IS_ERR(counter)) + return counter; + + err = devm_add_action_or_reset(dev, devm_counter_put, counter); + if (err < 0) + return ERR_PTR(err); + + return counter; +} +EXPORT_SYMBOL_GPL(devm_counter_alloc); + +/** + * devm_counter_add - complete registration of a counter + * @dev: the device to register the release callback for + * @counter: the counter to add + * + * This is the device managed version of counter_add(). It registers a cleanup + * callback to care for calling counter_unregister(). + */ +int devm_counter_add(struct device *dev, + struct counter_device *const counter) +{ + int err; + + err = counter_add(counter); + if (err < 0) + return err; + + return devm_add_action_or_reset(dev, devm_counter_release, counter); +} +EXPORT_SYMBOL_GPL(devm_counter_add); + #define COUNTER_DEV_MAX 256 static int __init counter_init(void) diff --git a/include/linux/counter.h b/include/linux/counter.h index 8daaa38c71d8..f1350a43cd48 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -327,14 +327,29 @@ struct counter_device { spinlock_t events_in_lock; struct mutex events_out_lock; struct mutex ops_exist_lock; + + /* + * This can go away once all drivers are converted to + * counter_alloc()/counter_add(). + */ + bool legacy_device; }; void *counter_priv(const struct counter_device *const counter); int counter_register(struct counter_device *const counter); + +struct counter_device *counter_alloc(size_t sizeof_priv); +void counter_put(struct counter_device *const counter); +int counter_add(struct counter_device *const counter); + void counter_unregister(struct counter_device *const counter); int devm_counter_register(struct device *dev, struct counter_device *const counter); +struct counter_device *devm_counter_alloc(struct device *dev, + size_t sizeof_priv); +int devm_counter_add(struct device *dev, + struct counter_device *const counter); void counter_push_event(struct counter_device *const counter, const u8 event, const u8 channel); From patchwork Wed Dec 29 15:44:32 2021 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: 12701000 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0A3CC433FE for ; Wed, 29 Dec 2021 15:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240614AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240601AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 635FAC061401 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qU-8c; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8F-007KHK-VV; Wed, 29 Dec 2021 16:44:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8F-00014b-3L; Wed, 29 Dec 2021 16:44:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jonathan Corbet Subject: [PATCH v3 14/23] counter: Update documentation for new counter registration functions Date: Wed, 29 Dec 2021 16:44:32 +0100 Message-Id: <20211229154441.38045-15-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1617; h=from:subject; bh=TASnXEH0lKlhSbBqFcgfSSsxVpWQVBj8v5aw8rDjyLo=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJAbsujyQnO74nW8GN1Q48yFonVn/gcNuRf6YZz YmlfROKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCQAAKCRDB/BR4rcrsCeMsB/ 9Ph8A0sFeBLDxXqgu3t8qiOeUrzOpZ9klRNgk2lgvwiF4Goqex/TlX25PIc/s7glKbtRb14qqEbyFw 8Xf/w1msF0RGsaikCmcU4Mwohi4/uiZwPRchi5DSz5lHDUdnT7NnU/wbDRqJ1okHnvhdvtOX6FtS5m mHM5YE6dcgBA24qjpDI95ayOtLD8oU9/t+J3QXNidpYWulgmaf5G4ZsnjsiItkSdETV9CRpbESD78e D1R1VFBgN3s6+IBp9CgfYCbPEgnWX0OmoQdlqcMP77sP3lf6uyocPhwH2H/ska1pQzzzylVxbV2lNJ 5v/Wy1e3ohI/bN+zyrnornC1wv9SkS 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org In order to replace the counter registration API also update the documentation to the new way. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- Documentation/driver-api/generic-counter.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst index 1b487a331467..71ccc30e586b 100644 --- a/Documentation/driver-api/generic-counter.rst +++ b/Documentation/driver-api/generic-counter.rst @@ -262,11 +262,11 @@ order to communicate with the device: to read and write various Signals and Counts, and to set and get the "action mode" and "function mode" for various Synapses and Counts respectively. -A defined counter_device structure may be registered to the system by -passing it to the counter_register function, and unregistered by passing -it to the counter_unregister function. Similarly, the -devm_counter_register function may be used if device memory-managed -registration is desired. +A counter_device structure is allocated using counter_alloc() and then +registered to the system by passing it to the counter_add() function, and +unregistered by passing it to the counter_unregister function. There are +device managed variants of these functions: devm_counter_alloc() and +devm_counter_add(). The struct counter_comp structure is used to define counter extensions for Signals, Synapses, and Counts. From patchwork Wed Dec 29 15:44:33 2021 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: 12701001 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90275C433EF for ; Wed, 29 Dec 2021 15:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240611AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240591AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 4B879C06173E for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qW-8c; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHN-5x; Wed, 29 Dec 2021 16:44:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8F-00014e-9l; Wed, 29 Dec 2021 16:44:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Syed Nayyar Waris Subject: [PATCH v3 15/23] counter: 104-quad-8: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:33 +0100 Message-Id: <20211229154441.38045-16-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3490; h=from:subject; bh=fCwyTDvkVPq0a+mwmGBMlzNOFeaz0oQeWCpaw+ebsCk=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJEgyRnLmtOQ2bWK6PbcaKTiAwfXUzswJ1eUg0F iebCyaeJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCRAAKCRDB/BR4rcrsCf7NB/ 9vCyyh9i9tGeTGUx6UzwbkJZQRIHn5/KeaRnYmzLPtNXFgFtfhIa1XzsmfjrZ58tjTViTc28bVVndG jZoCOsmcBQro8SHLesJN5GOuMeYrUyhwla05Z81Jv3hPEZduh+2eAQDM6dmfwVLc9hA21uzSN1c6w1 YIG/mtfCl6DrGuZd/pjNo7zVDZ7kXs4h2vZOrt3GMEh+63oF+NeP8Fwv2b8Y7E2E0ovLp/gZesdCX4 Z6vjPK+csL169LDE3jMY54iyDDYWxIa6uXIRVjBj1bNtOwICUT7WfzGTcSlAOg/zgmq8HCTLJzb8eA kmLMJ2ou6L/655zSGEbfPGplJZpY/t 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: f1d8a071d45b ("counter: 104-quad-8: Add Generic Counter interface support") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/104-quad-8.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 6e5286cd1d4e..680c7ba943a4 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -52,7 +52,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers"); */ struct quad8 { spinlock_t lock; - struct counter_device counter; unsigned int fck_prescaler[QUAD8_NUM_COUNTERS]; unsigned int preset[QUAD8_NUM_COUNTERS]; unsigned int count_mode[QUAD8_NUM_COUNTERS]; @@ -1085,7 +1084,8 @@ static struct counter_count quad8_counts[] = { static irqreturn_t quad8_irq_handler(int irq, void *private) { - struct quad8 *const priv = private; + struct counter_device *counter = private; + struct quad8 *const priv = counter_priv(counter); const unsigned long base = priv->base; unsigned long irq_status; unsigned long channel; @@ -1116,7 +1116,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private) continue; } - counter_push_event(&priv->counter, event, channel); + counter_push_event(counter, event, channel); } /* Clear pending interrupts on device */ @@ -1127,6 +1127,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private) static int quad8_probe(struct device *dev, unsigned int id) { + struct counter_device *counter; struct quad8 *priv; int i, j; unsigned int base_offset; @@ -1138,19 +1139,19 @@ static int quad8_probe(struct device *dev, unsigned int id) return -EBUSY; } - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); /* Initialize Counter device and driver data */ - priv->counter.name = dev_name(dev); - priv->counter.parent = dev; - priv->counter.ops = &quad8_ops; - priv->counter.counts = quad8_counts; - priv->counter.num_counts = ARRAY_SIZE(quad8_counts); - priv->counter.signals = quad8_signals; - priv->counter.num_signals = ARRAY_SIZE(quad8_signals); - priv->counter.priv = priv; + counter->name = dev_name(dev); + counter->parent = dev; + counter->ops = &quad8_ops; + counter->counts = quad8_counts; + counter->num_counts = ARRAY_SIZE(quad8_counts); + counter->signals = quad8_signals; + counter->num_signals = ARRAY_SIZE(quad8_signals); priv->base = base[id]; spin_lock_init(&priv->lock); @@ -1192,11 +1193,15 @@ static int quad8_probe(struct device *dev, unsigned int id) outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP); err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED, - priv->counter.name, priv); + counter->name, counter); if (err) return err; - return devm_counter_register(dev, &priv->counter); + err = devm_counter_add(dev, counter); + if (err < 0) + return dev_err_probe(dev, err, "Failed to add counter\n"); + + return 0; } static struct isa_driver quad8_driver = { From patchwork Wed Dec 29 15:44:34 2021 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: 12701009 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58D60C433FE for ; Wed, 29 Dec 2021 15:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240653AbhL2PpA (ORCPT ); Wed, 29 Dec 2021 10:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240609AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 8EE5BC061757 for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qZ-8c; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHS-Rb; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8F-00014w-Fd; Wed, 29 Dec 2021 16:44:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Oleksij Rempel , Ahmad Fatoum Subject: [PATCH v3 16/23] counter: interrupt-cnt: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:34 +0100 Message-Id: <20211229154441.38045-17-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2847; h=from:subject; bh=kSjVLBg3kmMU/LwOxftyB5QQVKub9wY1wnwJYxRqekI=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJI77tb9cuupSVHRrCAbwBzawT6ofIjcM5nYjmp M9Ow8TKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCSAAKCRDB/BR4rcrsCSmLB/ 45xChVJZ8rozJ11d198dfGEtgm+WUK4QKU2H3GjOxAfpO017MAYC/3MgyA4DvP2qB0M+h5UP6SNhnC kNXRZ2Ay0EDFvhDzeNldieBZO1u5RGqs+nzYcTCTQNbYuCDlr4wx5Aqja684QspTihwGgRuaykp4HV RzWdscFRL93vkeosVhNJFHoniysLio/8xQ+onXTb3n5p/ZN8oQKrINyqfEePBmvZ7Uv2B5jtceedhJ Y/xC+MwbAcmwVPS/xB1PsRiN9SYcSEJaZA1/eWVpobMX7xCcPqVI6pVdh7xzJ/6UjQCobO3OfVFac3 eiZhsWy/zDeO1FP/wGzWgGUy+xfXly 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index 4bf706ef46e2..9e99702470c2 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -16,7 +16,6 @@ struct interrupt_cnt_priv { atomic_t count; - struct counter_device counter; struct gpio_desc *gpio; int irq; bool enabled; @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = { static int interrupt_cnt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct counter_device *counter; struct interrupt_cnt_priv *priv; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); priv->irq = platform_get_irq_optional(pdev, 0); if (priv->irq == -ENXIO) @@ -184,8 +185,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev) if (!priv->signals.name) return -ENOMEM; - priv->counter.signals = &priv->signals; - priv->counter.num_signals = 1; + counter->signals = &priv->signals; + counter->num_signals = 1; priv->synapses.actions_list = interrupt_cnt_synapse_actions; priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions); @@ -199,12 +200,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev) priv->cnts.ext = interrupt_cnt_ext; priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext); - priv->counter.priv = priv; - priv->counter.name = dev_name(dev); - priv->counter.parent = dev; - priv->counter.ops = &interrupt_cnt_ops; - priv->counter.counts = &priv->cnts; - priv->counter.num_counts = 1; + counter->name = dev_name(dev); + counter->parent = dev; + counter->ops = &interrupt_cnt_ops; + counter->counts = &priv->cnts; + counter->num_counts = 1; irq_set_status_flags(priv->irq, IRQ_NOAUTOEN); ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr, @@ -213,7 +213,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev) if (ret) return ret; - return devm_counter_register(dev, &priv->counter); + ret = devm_counter_add(dev, counter); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to add counter\n"); + + return 0; } static const struct of_device_id interrupt_cnt_of_match[] = { From patchwork Wed Dec 29 15:44:35 2021 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: 12701013 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FC93C4332F for ; Wed, 29 Dec 2021 15:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240671AbhL2PpC (ORCPT ); Wed, 29 Dec 2021 10:45:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240613AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44: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 B1E93C06175C for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qX-8d; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHT-Lh; Wed, 29 Dec 2021 16:44:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8F-00015A-Ls; Wed, 29 Dec 2021 16:44:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jarkko Nikula Subject: [PATCH v3 17/23] counter: intel-qep: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:35 +0100 Message-Id: <20211229154441.38045-18-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2585; h=from:subject; bh=mzTA/0SVSt6Zg5a8YAIzLvS/FUvKzhlK/TyLmD2WeP8=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJM/e4/TFKfAT0n53Xuj6xEs/f60hAC0BztFLCd e0evtYOJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCTAAKCRDB/BR4rcrsCQNmCA CIAfdB8EWPt1sa0ZIAhRgiIU6DvDdPAHCdn7HgAGiAgBk2GPwQL+EdudTCFLZObS3VivLEwQ6u9wFm zRIqwnvH5zYXbhxN7EM1aYftSskhgDVSsQz5MT5spWKRZp5H+FWxx9WNgFT3fismz1v4Su5XIn/Q6F rIyWqNEgmeMzz058SlUc7aXO0zs/oly0EPhKUGCc7Aq+kuJn/AYrnHaruY2PPWHbLoPMPxIb0f45d2 uzlEEZTM0f+kIMfhKZz+IWbF1Qj+XyG+mLR+WHk09K4DV4xBkBzKH0q21c/3DNSkmxnZDY3vdmAU4c Cg7ecShnEIwUD4yu69eH9tfqmtM0HX 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König Acked-by: Jarkko Nikula Tested-by: Jarkko Nikula --- drivers/counter/intel-qep.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 8f84a48508ac..47a6a9dfc9e8 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -63,7 +63,6 @@ #define INTEL_QEP_CLK_PERIOD_NS 10 struct intel_qep { - struct counter_device counter; struct mutex lock; struct device *dev; void __iomem *regs; @@ -392,14 +391,16 @@ static struct counter_count intel_qep_counter_count[] = { static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id) { + struct counter_device *counter; struct intel_qep *qep; struct device *dev = &pci->dev; void __iomem *regs; int ret; - qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL); - if (!qep) + counter = devm_counter_alloc(dev, sizeof(*qep)); + if (!counter) return -ENOMEM; + qep = counter_priv(counter); ret = pcim_enable_device(pci); if (ret) @@ -422,20 +423,23 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id) intel_qep_init(qep); pci_set_drvdata(pci, qep); - qep->counter.name = pci_name(pci); - qep->counter.parent = dev; - qep->counter.ops = &intel_qep_counter_ops; - qep->counter.counts = intel_qep_counter_count; - qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count); - qep->counter.signals = intel_qep_signals; - qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals); - qep->counter.priv = qep; + counter->name = pci_name(pci); + counter->parent = dev; + counter->ops = &intel_qep_counter_ops; + counter->counts = intel_qep_counter_count; + counter->num_counts = ARRAY_SIZE(intel_qep_counter_count); + counter->signals = intel_qep_signals; + counter->num_signals = ARRAY_SIZE(intel_qep_signals); qep->enabled = false; pm_runtime_put(dev); pm_runtime_allow(dev); - return devm_counter_register(&pci->dev, &qep->counter); + ret = devm_counter_add(&pci->dev, counter); + if (ret < 0) + return dev_err_probe(&pci->dev, ret, "Failed to add counter\n"); + + return 0; } static void intel_qep_remove(struct pci_dev *pci) From patchwork Wed Dec 29 15:44:36 2021 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: 12701007 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBB32C4167D for ; Wed, 29 Dec 2021 15:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240639AbhL2Po7 (ORCPT ); Wed, 29 Dec 2021 10:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240608AbhL2Po4 (ORCPT ); Wed, 29 Dec 2021 10:44:56 -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 9B8B6C06175A for ; Wed, 29 Dec 2021 07:44: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 1n2b8H-0006qY-8c; Wed, 29 Dec 2021 16:44:53 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHU-Qa; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8F-00015D-Qw; Wed, 29 Dec 2021 16:44:51 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Patrick Havelange Subject: [PATCH v3 18/23] counter: ftm-quaddec: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:36 +0100 Message-Id: <20211229154441.38045-19-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2604; h=from:subject; bh=dEjv5+WDibUQXP80AqPnPObQXmoq70SGZBTr6K5rpzQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJPVcEOLoF6nRh7AcGLwuW1Sbhc0blFhQMHBrzK WdyQ1OaJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCTwAKCRDB/BR4rcrsCYzJCA CHNsAeYsS+8fSEr++mFdlWXII/Zatlb0zvCK9hWoC11V7q9hKCaLq7Z7nRxCWdL8uelDrlQR93fFqd 6Umt9iqd/u528xP5PX87yB3Gw4riu96l5kO9lrJ34c/4YfEMQvYK4nPzULbgj0Z+P56W0EkKjp6YVe +a5Z8hSVmtq0OM5KHTi41Jcl8QNF1wPSPVfzNFD7uwT++Y8NSAYWUaeTcLYidHEKmFtXami2bm0tpv kXPawvtbroMZwv0y6aPYLejlOSRoYiCyF1HJZxQLMRmjxm5EFH4bLydyCA1Cog4kPLWYm7nc76cE9e FJBJW651AjL1qXT0YgT1q01lx+30mI 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/ftm-quaddec.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index f5d92df6a611..2a58582a9df4 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -26,7 +26,6 @@ }) struct ftm_quaddec { - struct counter_device counter; struct platform_device *pdev; void __iomem *ftm_base; bool big_endian; @@ -259,15 +258,17 @@ static struct counter_count ftm_quaddec_counts = { static int ftm_quaddec_probe(struct platform_device *pdev) { + struct counter_device *counter; struct ftm_quaddec *ftm; struct device_node *node = pdev->dev.of_node; struct resource *io; int ret; - ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL); - if (!ftm) + counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm)); + if (!counter) return -ENOMEM; + ftm = counter_priv(counter); io = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!io) { @@ -283,14 +284,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to map memory region\n"); return -EINVAL; } - ftm->counter.name = dev_name(&pdev->dev); - ftm->counter.parent = &pdev->dev; - ftm->counter.ops = &ftm_quaddec_cnt_ops; - ftm->counter.counts = &ftm_quaddec_counts; - ftm->counter.num_counts = 1; - ftm->counter.signals = ftm_quaddec_signals; - ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals); - ftm->counter.priv = ftm; + counter->name = dev_name(&pdev->dev); + counter->parent = &pdev->dev; + counter->ops = &ftm_quaddec_cnt_ops; + counter->counts = &ftm_quaddec_counts; + counter->num_counts = 1; + counter->signals = ftm_quaddec_signals; + counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals); mutex_init(&ftm->ftm_quaddec_mutex); @@ -300,9 +300,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev) if (ret) return ret; - ret = devm_counter_register(&pdev->dev, &ftm->counter); + ret = devm_counter_add(&pdev->dev, counter); if (ret) - return ret; + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); return 0; } From patchwork Wed Dec 29 15:44:37 2021 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: 12701015 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7072EC433EF for ; Wed, 29 Dec 2021 15:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240705AbhL2PpG (ORCPT ); Wed, 29 Dec 2021 10:45:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240665AbhL2PpB (ORCPT ); Wed, 29 Dec 2021 10:45:01 -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 8194CC061574 for ; Wed, 29 Dec 2021 07:45:01 -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 1n2b8M-0006qa-0x; Wed, 29 Dec 2021 16:44:58 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8G-007KHX-Ub; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8G-00015J-0H; Wed, 29 Dec 2021 16:44:52 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Kamel Bouhara Subject: [PATCH v3 19/23] counter: microchip-tcb-capture: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:37 +0100 Message-Id: <20211229154441.38045-20-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2719; h=from:subject; bh=ilok6S7IEjL22MS++d5HMtruBUuqxpO8sZvUtAfS3SU=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJTXvq6aiieYdSsHVOhmkcvivxdAX/2CRtHBJXr 3MNKaPKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCUwAKCRDB/BR4rcrsCVuXB/ 99b1RfXLQZ290Jqd+ClUlB3jMSHDwYZ+u5kZGNayBj6w2DN8gtYXJSKg4JXTGiPRSLaLKNhg6M2Bg0 JWNK1qfqLY+Dn9AXsbZzwWOW0IWHlblY1Vn4k4/IHnlR+yFcHjQ42lD0zqh0XcgQwDIVqrhNRIU4TL VJoajEPpgL9HoavmXY7P/azae2ABHQtWvLBEQpTiDoOE20X2WX9UQUiinY1AP/bUbvfwIUcKtPkEg+ OyJj7M7Nt3umXmVGL6n7GjLX/KSrTBcDkEGQJELnS36r3jDVjuGhIWBnPK1hydox6bWZwZ2JpsPo5D Cv+UHzifL9f27MpF6W8qD912kHobLs 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: 106b104137fd ("counter: Add microchip TCB capture counter") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/microchip-tcb-capture.c | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index 1b56b7444668..70c1d28546be 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -24,7 +24,6 @@ struct mchp_tc_data { const struct atmel_tcb_config *tc_cfg; - struct counter_device counter; struct regmap *regmap; int qdec_mode; int num_channels; @@ -296,6 +295,7 @@ static int mchp_tc_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; const struct atmel_tcb_config *tcb_config; const struct of_device_id *match; + struct counter_device *counter; struct mchp_tc_data *priv; char clk_name[7]; struct regmap *regmap; @@ -303,9 +303,10 @@ static int mchp_tc_probe(struct platform_device *pdev) int channel; int ret, i; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(&pdev->dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); match = of_match_node(atmel_tc_of_match, np->parent); tcb_config = match->data; @@ -360,16 +361,19 @@ static int mchp_tc_probe(struct platform_device *pdev) priv->tc_cfg = tcb_config; priv->regmap = regmap; - priv->counter.name = dev_name(&pdev->dev); - priv->counter.parent = &pdev->dev; - priv->counter.ops = &mchp_tc_ops; - priv->counter.num_counts = ARRAY_SIZE(mchp_tc_counts); - priv->counter.counts = mchp_tc_counts; - priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals); - priv->counter.signals = mchp_tc_count_signals; - priv->counter.priv = priv; - - return devm_counter_register(&pdev->dev, &priv->counter); + counter->name = dev_name(&pdev->dev); + counter->parent = &pdev->dev; + counter->ops = &mchp_tc_ops; + counter->num_counts = ARRAY_SIZE(mchp_tc_counts); + counter->counts = mchp_tc_counts; + counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals); + counter->signals = mchp_tc_count_signals; + + ret = devm_counter_add(&pdev->dev, counter); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); + + return 0; } static const struct of_device_id mchp_tc_dt_ids[] = { From patchwork Wed Dec 29 15:44:38 2021 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: 12701019 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CEB7C433EF for ; Wed, 29 Dec 2021 15:45:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240743AbhL2PpM (ORCPT ); Wed, 29 Dec 2021 10:45:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240668AbhL2PpC (ORCPT ); Wed, 29 Dec 2021 10:45:02 -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 EDA79C061574 for ; Wed, 29 Dec 2021 07:45:01 -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 1n2b8N-0006qb-4w; Wed, 29 Dec 2021 16:44:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8H-007KHc-FP; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8G-00015Z-5y; Wed, 29 Dec 2021 16:44:52 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 20/23] counter: stm32-timer-cnt: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:38 +0100 Message-Id: <20211229154441.38045-21-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2408; h=from:subject; bh=yamPh52MWvtBuq1kwhHgzE8DC1LccrX53waJcMLV5Ao=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJX2YDALYtMQDBjFVY7z1y0vh4yin3H9exKf8He MpsunwCJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCVwAKCRDB/BR4rcrsCX2TB/ 4l6dwzOcg3gaNLauntF56BmjfxPhW8LKusPK96eCoKKVv1XVpK2d0OHMrSDwvCnfTE2sCns1muZr/A V8BkrwPtLWadBPofuKRCAZl5T2f9Jme3vQJy3E/SHrE5bg1u+8KcdBpbc/KfkAsc9MabSNiiW+kVPZ 3bnCQ8SA+Mf2kdBNIwos2dwUO1kolUsMp5vbZcWqhgl357yZQ6tTP3aiRCFw5lWYXkYUaGclBmnZEG Su6sxkO+OS4JysLsVNUdXtrUHIPHNgZrcIozmmk7dU7zAqAKHdzyrJf334yRTn50ynntq7xPIRiSiG z9qmwgaHSlUh1JPXodXOFngvE+DU0Z 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 4b05b198a8d8..5779ae7c73cf 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -29,7 +29,6 @@ struct stm32_timer_regs { }; struct stm32_timer_cnt { - struct counter_device counter; struct regmap *regmap; struct clk *clk; u32 max_arr; @@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev) struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); struct device *dev = &pdev->dev; struct stm32_timer_cnt *priv; + struct counter_device *counter; + int ret; if (IS_ERR_OR_NULL(ddata)) return -EINVAL; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); + priv->regmap = ddata->regmap; priv->clk = ddata->clk; priv->max_arr = ddata->max_arr; - priv->counter.name = dev_name(dev); - priv->counter.parent = dev; - priv->counter.ops = &stm32_timer_cnt_ops; - priv->counter.counts = &stm32_counts; - priv->counter.num_counts = 1; - priv->counter.signals = stm32_signals; - priv->counter.num_signals = ARRAY_SIZE(stm32_signals); - priv->counter.priv = priv; + counter->name = dev_name(dev); + counter->parent = dev; + counter->ops = &stm32_timer_cnt_ops; + counter->counts = &stm32_counts; + counter->num_counts = 1; + counter->signals = stm32_signals; + counter->num_signals = ARRAY_SIZE(stm32_signals); platform_set_drvdata(pdev, priv); /* Register Counter device */ - return devm_counter_register(dev, &priv->counter); + ret = devm_counter_add(dev, counter); + if (ret < 0) + dev_err_probe(dev, ret, "Failed to add counter\n"); + + return ret; } static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev) From patchwork Wed Dec 29 15:44:39 2021 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: 12701018 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A82F3C433FE for ; Wed, 29 Dec 2021 15:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240724AbhL2PpL (ORCPT ); Wed, 29 Dec 2021 10:45:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240673AbhL2PpC (ORCPT ); Wed, 29 Dec 2021 10:45:02 -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 66F2AC06173F for ; Wed, 29 Dec 2021 07:45:02 -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 1n2b8N-0006qd-52; Wed, 29 Dec 2021 16:44:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8H-007KHf-NK; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8G-00015t-Bc; Wed, 29 Dec 2021 16:44:52 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:39 +0100 Message-Id: <20211229154441.38045-22-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2830; h=from:subject; bh=Z30Y5klYFwnFI5jJS4Jj6GD8bn4cD3tqmAq9j/Gq+4c=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJacwTnYraxEudTA2g4uyLsOHdO8G35dTdIsTc6 TGeqWNSJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCWgAKCRDB/BR4rcrsCdEXB/ 9ak1i59flop7l6GePuduqIvXEWIS7FcFHzY5YVx4oZA854nfbqb6wl9rFw4ITFyrc3lnLgG7w4oeS8 yZoTQW+0GuyOXCm1gGExDXyVjGUHCpmqMLqUUKMrymaA72Z+xVR/MyCRlqxYnycc5h3k6g2VDIg/pa EoUWnI00EeeXOJtG3BUhSmS+cmI0bAU5O0N5vEdGujTrMFxImHRE+xULBSye/Koj/UdXiYHZNZ/kBO PrP/0JF9c8MN/iw4IJZH6vm2h+d9SGRpkpdP++575L9PEWcxg0uN/Fx7Jm93YTvOmYN5XeIvLUf3MZ 69FznVb2cDpbc4C9pkWDl1rGJhK9mb 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index 9cf00e929cc0..68031d93ce89 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -20,7 +20,6 @@ #include struct stm32_lptim_cnt { - struct counter_device counter; struct device *dev; struct regmap *regmap; struct clk *clk; @@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = { static int stm32_lptim_cnt_probe(struct platform_device *pdev) { struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent); + struct counter_device *counter; struct stm32_lptim_cnt *priv; + int ret; if (IS_ERR_OR_NULL(ddata)) return -EINVAL; - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(&pdev->dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); priv->dev = &pdev->dev; priv->regmap = ddata->regmap; @@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) priv->ceiling = STM32_LPTIM_MAX_ARR; /* Initialize Counter device */ - priv->counter.name = dev_name(&pdev->dev); - priv->counter.parent = &pdev->dev; - priv->counter.ops = &stm32_lptim_cnt_ops; + counter->name = dev_name(&pdev->dev); + counter->parent = &pdev->dev; + counter->ops = &stm32_lptim_cnt_ops; if (ddata->has_encoder) { - priv->counter.counts = &stm32_lptim_enc_counts; - priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals); + counter->counts = &stm32_lptim_enc_counts; + counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals); } else { - priv->counter.counts = &stm32_lptim_in1_counts; - priv->counter.num_signals = 1; + counter->counts = &stm32_lptim_in1_counts; + counter->num_signals = 1; } - priv->counter.num_counts = 1; - priv->counter.signals = stm32_lptim_cnt_signals; - priv->counter.priv = priv; + counter->num_counts = 1; + counter->signals = stm32_lptim_cnt_signals; platform_set_drvdata(pdev, priv); - return devm_counter_register(&pdev->dev, &priv->counter); + ret = devm_counter_add(&pdev->dev, counter); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n"); + + return 0; } #ifdef CONFIG_PM_SLEEP From patchwork Wed Dec 29 15:44:40 2021 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: 12701012 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45F16C43217 for ; Wed, 29 Dec 2021 15:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240680AbhL2PpD (ORCPT ); Wed, 29 Dec 2021 10:45:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240615AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44: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 D8B5EC061574 for ; Wed, 29 Dec 2021 07:44: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 1n2b8I-0006qc-BF; Wed, 29 Dec 2021 16:44:54 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8H-007KHg-KV; Wed, 29 Dec 2021 16:44:52 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8G-00015w-GG; Wed, 29 Dec 2021 16:44:52 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, David Lechner Subject: [PATCH v3 22/23] counter: ti-eqep: Convert to new counter registration Date: Wed, 29 Dec 2021 16:44:40 +0100 Message-Id: <20211229154441.38045-23-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2858; h=from:subject; bh=ZlowvYTI9941w6RCHKBdF4qFDgy7g9cAVVM3FyXf/A8=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJfIwLz2TtR6847F+Rq84u8nZTBQZQ4BH7tlKaB M0aqXmCJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCXwAKCRDB/BR4rcrsCQxLB/ 9S5VHi7UMArSsD3dbs/xaH27Q8AXg7HRU+JrLO8Gnk4F4AlPBR0tz437D6GSm9SkFVgmOvqiyN4dMj 21hJbTrItCYOf9qXqVH7GcmP0FEuizl8TPA6R6LlkvO9GdHmAoR9t5bNDoix/kQA7zkvJ2Oo2I+QhB ddpN7SWep7dcZCQ1+bIhF6EXVHVyhQVAcjzQUhQu/1dZinktKjMVK59GebpbtbxEjopJ7rkJrOzete 1VOYTYR1CzIlx3O4I2YcicwU4h81fYCgCXr7M233McEFSz6XvGlpqSOnBdWk5VaW7DA1d8/gTfnqDy 01tOLpbpxbB9H57o93jR8jFvkFVhbq 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This fixes device lifetime issues where it was possible to free a live struct device. Fixes: f213729f6796 ("counter: new TI eQEP driver") Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König Acked-by: David Lechner --- drivers/counter/ti-eqep.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index 2c70b900a6cf..0489d26eb47c 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -373,13 +373,15 @@ static const struct regmap_config ti_eqep_regmap16_config = { static int ti_eqep_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct counter_device *counter; struct ti_eqep_cnt *priv; void __iomem *base; int err; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) + counter = devm_counter_alloc(dev, sizeof(*priv)); + if (!counter) return -ENOMEM; + priv = counter_priv(counter); base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) @@ -395,16 +397,15 @@ static int ti_eqep_probe(struct platform_device *pdev) if (IS_ERR(priv->regmap16)) return PTR_ERR(priv->regmap16); - priv->counter.name = dev_name(dev); - priv->counter.parent = dev; - priv->counter.ops = &ti_eqep_counter_ops; - priv->counter.counts = ti_eqep_counts; - priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts); - priv->counter.signals = ti_eqep_signals; - priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals); - priv->counter.priv = priv; + counter->name = dev_name(dev); + counter->parent = dev; + counter->ops = &ti_eqep_counter_ops; + counter->counts = ti_eqep_counts; + counter->num_counts = ARRAY_SIZE(ti_eqep_counts); + counter->signals = ti_eqep_signals; + counter->num_signals = ARRAY_SIZE(ti_eqep_signals); - platform_set_drvdata(pdev, priv); + platform_set_drvdata(pdev, counter); /* * Need to make sure power is turned on. On AM33xx, this comes from the @@ -414,7 +415,7 @@ static int ti_eqep_probe(struct platform_device *pdev) pm_runtime_enable(dev); pm_runtime_get_sync(dev); - err = counter_register(&priv->counter); + err = counter_add(counter); if (err < 0) { pm_runtime_put_sync(dev); pm_runtime_disable(dev); @@ -426,10 +427,10 @@ static int ti_eqep_probe(struct platform_device *pdev) static int ti_eqep_remove(struct platform_device *pdev) { - struct ti_eqep_cnt *priv = platform_get_drvdata(pdev); + struct counter_device *counter = platform_get_drvdata(pdev); struct device *dev = &pdev->dev; - counter_unregister(&priv->counter); + counter_unregister(counter); pm_runtime_put_sync(dev); pm_runtime_disable(dev); From patchwork Wed Dec 29 15:44:41 2021 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: 12701023 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28F7FC433EF for ; Wed, 29 Dec 2021 15:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240605AbhL2PpD (ORCPT ); Wed, 29 Dec 2021 10:45:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240616AbhL2Po5 (ORCPT ); Wed, 29 Dec 2021 10:44: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 13F48C06173E for ; Wed, 29 Dec 2021 07:44: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 1n2b8I-0006sE-HY; Wed, 29 Dec 2021 16:44:54 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n2b8I-007KHh-4T; Wed, 29 Dec 2021 16:44:53 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1n2b8G-000162-MJ; Wed, 29 Dec 2021 16:44:52 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, kernel@pengutronix.de, Jonathan Cameron , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 23/23] counter: remove old and now unused registration API Date: Wed, 29 Dec 2021 16:44:41 +0100 Message-Id: <20211229154441.38045-24-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> References: <20211229154441.38045-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5703; h=from:subject; bh=d+n4DdZbQkz6lWvicNyaheFb+rPgVDrBk6eJ2FPNHVA=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBhzIJj+NcEdqt/DjAYBt+///jJf1VqDzQwBEQU4TsO Ll0kPLaJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYcyCYwAKCRDB/BR4rcrsCWMcB/ 9H0crukzp2NJOXiQFRnWPtk0YaX2hx9XviQikRmf57UPC+EE8lKGYmRwo4k3N1bTNgaEHJXcAmIEcD ldm+2IHCa6SaqnXnrUBjbRdzINAncMMbuzTWso/GVLBL2yoCH62vI57CVsnioYtww8biZ5lGkyXBMR Z3uRYURSASGyRj+xF5UliMBoRBhVHJ/93zFQzQTS6CqNUTAhTt2ahyoMqu/BAq5XGvM4dvbdFNbfsv jfd5w9DJBL4Y01NgFpZhS3Yxtm6WyIRWe1oJ2ezYZVeliIiw9I/a07sUbnud2PXv5LKe92vchd7uSX Ys0e1ckCHVR6XpKsvMuG3zlpGBN379 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-iio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Usage of counter_register() yields issues in device lifetime tracking. All drivers were converted to the new API, so the old one can go away. Reviewed-by: Jonathan Cameron Acked-by: William Breathitt Gray Signed-off-by: Uwe Kleine-König --- drivers/counter/counter-core.c | 100 ++------------------------------- include/linux/counter.h | 12 ---- 2 files changed, 4 insertions(+), 108 deletions(-) diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c index b3fa15bbcbdb..7e0957eea094 100644 --- a/drivers/counter/counter-core.c +++ b/drivers/counter/counter-core.c @@ -43,8 +43,7 @@ static void counter_device_release(struct device *dev) counter_chrdev_remove(counter); ida_free(&counter_ida, dev->id); - if (!counter->legacy_device) - kfree(container_of(counter, struct counter_device_allochelper, counter)); + kfree(container_of(counter, struct counter_device_allochelper, counter)); } static struct device_type counter_device_type = { @@ -67,76 +66,13 @@ static dev_t counter_devt; */ void *counter_priv(const struct counter_device *const counter) { - if (counter->legacy_device) { - return counter->priv; - } else { - struct counter_device_allochelper *ch = - container_of(counter, struct counter_device_allochelper, counter); + struct counter_device_allochelper *ch = + container_of(counter, struct counter_device_allochelper, counter); - return &ch->privdata; - } + return &ch->privdata; } EXPORT_SYMBOL_GPL(counter_priv); -/** - * counter_register - register Counter to the system - * @counter: pointer to Counter to register - * - * This function registers a Counter to the system. A sysfs "counter" directory - * will be created and populated with sysfs attributes correlating with the - * Counter Signals, Synapses, and Counts respectively. - * - * RETURNS: - * 0 on success, negative error number on failure. - */ -int counter_register(struct counter_device *const counter) -{ - struct device *const dev = &counter->dev; - int id; - int err; - - counter->legacy_device = true; - - /* Acquire unique ID */ - id = ida_alloc(&counter_ida, GFP_KERNEL); - if (id < 0) - return id; - - mutex_init(&counter->ops_exist_lock); - - /* Configure device structure for Counter */ - dev->id = id; - dev->type = &counter_device_type; - dev->bus = &counter_bus_type; - dev->devt = MKDEV(MAJOR(counter_devt), id); - if (counter->parent) { - dev->parent = counter->parent; - dev->of_node = counter->parent->of_node; - } - device_initialize(dev); - - err = counter_sysfs_add(counter); - if (err < 0) - goto err_free_id; - - err = counter_chrdev_add(counter); - if (err < 0) - goto err_free_id; - - err = cdev_device_add(&counter->chrdev, dev); - if (err < 0) - goto err_remove_chrdev; - - return 0; - -err_remove_chrdev: - counter_chrdev_remove(counter); -err_free_id: - put_device(dev); - return err; -} -EXPORT_SYMBOL_GPL(counter_register); - /** * counter_alloc - allocate a counter_device * @sizeof_priv: size of the driver private data @@ -245,9 +181,6 @@ void counter_unregister(struct counter_device *const counter) wake_up(&counter->events_wait); mutex_unlock(&counter->ops_exist_lock); - - if (counter->legacy_device) - put_device(&counter->dev); } EXPORT_SYMBOL_GPL(counter_unregister); @@ -256,31 +189,6 @@ static void devm_counter_release(void *counter) counter_unregister(counter); } -/** - * devm_counter_register - Resource-managed counter_register - * @dev: device to allocate counter_device for - * @counter: pointer to Counter to register - * - * Managed counter_register. The Counter registered with this function is - * automatically unregistered on driver detach. This function calls - * counter_register internally. Refer to that function for more information. - * - * RETURNS: - * 0 on success, negative error number on failure. - */ -int devm_counter_register(struct device *dev, - struct counter_device *const counter) -{ - int err; - - err = counter_register(counter); - if (err < 0) - return err; - - return devm_add_action_or_reset(dev, devm_counter_release, counter); -} -EXPORT_SYMBOL_GPL(devm_counter_register); - static void devm_counter_put(void *counter) { counter_put(counter); diff --git a/include/linux/counter.h b/include/linux/counter.h index f1350a43cd48..9afa0f1e9cea 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -314,8 +314,6 @@ struct counter_device { struct counter_comp *ext; size_t num_ext; - void *priv; - struct device dev; struct cdev chrdev; struct list_head events_list; @@ -327,25 +325,15 @@ struct counter_device { spinlock_t events_in_lock; struct mutex events_out_lock; struct mutex ops_exist_lock; - - /* - * This can go away once all drivers are converted to - * counter_alloc()/counter_add(). - */ - bool legacy_device; }; void *counter_priv(const struct counter_device *const counter); -int counter_register(struct counter_device *const counter); - struct counter_device *counter_alloc(size_t sizeof_priv); void counter_put(struct counter_device *const counter); int counter_add(struct counter_device *const counter); void counter_unregister(struct counter_device *const counter); -int devm_counter_register(struct device *dev, - struct counter_device *const counter); struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv); int devm_counter_add(struct device *dev,