From nobody Wed Jul 1 13:29:19 2026 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 15A11C433F5 for ; Tue, 21 Dec 2021 10:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234265AbhLUKqK (ORCPT ); Tue, 21 Dec 2021 05:46:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbhLUKqH (ORCPT ); Tue, 21 Dec 2021 05:46:07 -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 1EB9BC061574 for ; Tue, 21 Dec 2021 02:46:07 -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 1mzcei-0005B5-O7; Tue, 21 Dec 2021 11:46:04 +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 1mzceh-005nfs-H5; Tue, 21 Dec 2021 11:46:02 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceg-0004BS-JV; Tue, 21 Dec 2021 11:46:02 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: William Breathitt Gray , Syed Nayyar Waris Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] counter: 104-quad-8: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:39 +0100 Message-Id: <20211221104546.214066-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=CnBH63zzo+tqIzwX0lexnwgBN96xH+nVjDGI1acY4RE=; m=WBq4e46WGgS0dLi5xghMITgc9qKFAxSgpTl9JAlgCl4=; p=LfndeIs0fXVbHBSKaxGOiyMpLhehIJekYg4LQfX76U4=; g=d7209755a97347fa53efe3344d0d29e29e1dbe0d X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsC8ACgkQwfwUeK3K7AkaRAf+OSR 4Unldn3jMWyf4io2BQ6yR/IlA0Gxf740sFVQKVw0NHMDBqtuxK2o3mU+57SK9JlSjqyquIYMlvdMB NZRSMWHgs6JBNjOMcEx1274bZLbjsRlj5fNixFOuVNBpy5prhWTlvxunMVraSFUl0eWUxLiMVkvmr 1JAr98qzo1UJLi2Ux1c2S5OE6xuU2+lna+xFqWorqi2+qTYKWsS7defGZ56e0k49almcjhdBMLYZM iKlqxljkvHnlw1/wXjKsgQ5tVAyN6doKDbexr9Vlfwy+sVnCXrzd5f9+1XAXZrukucVD6oqCb+HxY iNvUbrhUBmhtrQIS52tOnlr6FWZqpYw== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 5/17 up/down: 76/-172 (-96) Function old new delta quad8_function_write 612 648 +36 quad8_count_mode_write 296 312 +16 quad8_count_enable_write 232 248 +16 quad8_events_configure 384 388 +4 quad8_count_preset_enable_write 264 268 +4 quad8_signal_fck_prescaler_read 108 104 -4 quad8_count_enable_read 100 96 -4 quad8_synchronous_mode_set 304 296 -8 quad8_signal_cable_fault_read 240 232 -8 quad8_signal_cable_fault_enable_write 244 236 -8 quad8_index_polarity_set 200 192 -8 quad8_function_read 292 284 -8 quad8_count_read 304 296 -8 quad8_count_preset_write 160 152 -8 quad8_count_ceiling_read 216 208 -8 quad8_signal_read 212 200 -12 quad8_signal_cable_fault_enable_read 108 96 -12 quad8_probe 1116 1104 -12 quad8_error_noise_get 156 144 -12 quad8_direction_read 156 144 -12 quad8_action_read 836 824 -12 quad8_watch_validate 528 500 -28 Total: Before=3D11802, After=3D11706, chg -0.81% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/104-quad-8.c | 64 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 1cbd60aaed69..a9e75c70ad30 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -109,11 +109,16 @@ struct quad8 { #define QUAD8_CMR_QUADRATURE_X2 0x10 #define QUAD8_CMR_QUADRATURE_X4 0x18 =20 +static struct quad8 *quad8_from_counter(struct counter_device *counter) +{ + return container_of(counter, struct quad8, counter); +} + static int quad8_signal_read(struct counter_device *counter, struct counter_signal *signal, enum counter_signal_level *level) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); unsigned int state; =20 /* Only Index signal levels can be read */ @@ -131,7 +136,7 @@ static int quad8_signal_read(struct counter_device *cou= nter, static int quad8_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int base_offset =3D priv->base + 2 * count->id; unsigned int flags; unsigned int borrow; @@ -163,7 +168,7 @@ static int quad8_count_read(struct counter_device *coun= ter, static int quad8_count_write(struct counter_device *counter, struct counter_count *count, u64 val) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int base_offset =3D priv->base + 2 * count->id; unsigned long irqflags; int i; @@ -213,7 +218,7 @@ static int quad8_function_read(struct counter_device *c= ounter, struct counter_count *count, enum counter_function *function) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int id =3D count->id; unsigned long irqflags; =20 @@ -243,7 +248,7 @@ static int quad8_function_write(struct counter_device *= counter, struct counter_count *count, enum counter_function function) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int id =3D count->id; unsigned int *const quadrature_mode =3D priv->quadrature_mode + id; unsigned int *const scale =3D priv->quadrature_scale + id; @@ -305,7 +310,7 @@ static int quad8_direction_read(struct counter_device *= counter, struct counter_count *count, enum counter_count_direction *direction) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); unsigned int ud_flag; const unsigned int flag_addr =3D priv->base + 2 * count->id + 1; =20 @@ -335,7 +340,7 @@ static int quad8_action_read(struct counter_device *cou= nter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); int err; enum counter_function function; const size_t signal_a_id =3D count->synapses[0].signal->id; @@ -399,7 +404,7 @@ enum { =20 static int quad8_events_configure(struct counter_device *counter) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); unsigned long irq_enabled =3D 0; unsigned long irqflags; size_t channel; @@ -442,7 +447,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 =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); =20 if (watch->channel > QUAD8_NUM_COUNTERS - 1) return -EINVAL; @@ -497,7 +502,7 @@ static int quad8_index_polarity_get(struct counter_devi= ce *counter, struct counter_signal *signal, u32 *index_polarity) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id - 16; =20 *index_polarity =3D priv->index_polarity[channel_id]; @@ -509,7 +514,7 @@ static int quad8_index_polarity_set(struct counter_devi= ce *counter, struct counter_signal *signal, u32 index_polarity) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id - 16; const int base_offset =3D priv->base + 2 * channel_id + 1; unsigned long irqflags; @@ -538,7 +543,7 @@ static int quad8_synchronous_mode_get(struct counter_de= vice *counter, struct counter_signal *signal, u32 *synchronous_mode) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id - 16; =20 *synchronous_mode =3D priv->synchronous_mode[channel_id]; @@ -550,7 +555,7 @@ static int quad8_synchronous_mode_set(struct counter_de= vice *counter, struct counter_signal *signal, u32 synchronous_mode) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id - 16; const int base_offset =3D priv->base + 2 * channel_id + 1; unsigned long irqflags; @@ -589,7 +594,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 =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); =20 /* Map 104-QUAD-8 count mode to Generic Counter count mode */ switch (priv->count_mode[count->id]) { @@ -614,7 +619,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 =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); unsigned int count_mode; unsigned int mode_cfg; const int base_offset =3D priv->base + 2 * count->id + 1; @@ -661,7 +666,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 =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); =20 *enable =3D priv->ab_enable[count->id]; =20 @@ -671,7 +676,7 @@ static int quad8_count_enable_read(struct counter_devic= e *counter, static int quad8_count_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int base_offset =3D priv->base + 2 * count->id; unsigned long irqflags; unsigned int ior_cfg; @@ -699,7 +704,7 @@ static const char *const quad8_noise_error_states[] =3D= { static int quad8_error_noise_get(struct counter_device *counter, struct counter_count *count, u32 *noise_error) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); const int base_offset =3D priv->base + 2 * count->id + 1; =20 *noise_error =3D !!(inb(base_offset) & QUAD8_FLAG_E); @@ -710,7 +715,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 =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); =20 *preset =3D priv->preset[count->id]; =20 @@ -736,7 +741,7 @@ static void quad8_preset_register_set(struct quad8 *con= st priv, const int id, static int quad8_count_preset_write(struct counter_device *counter, struct counter_count *count, u64 preset) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); unsigned long irqflags; =20 /* Only 24-bit values are supported */ @@ -755,7 +760,7 @@ static int quad8_count_preset_write(struct counter_devi= ce *counter, static int quad8_count_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); unsigned long irqflags; =20 spin_lock_irqsave(&priv->lock, irqflags); @@ -780,7 +785,7 @@ static int quad8_count_ceiling_read(struct counter_devi= ce *counter, static int quad8_count_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 ceiling) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); unsigned long irqflags; =20 /* Only 24-bit values are supported */ @@ -807,7 +812,7 @@ static int quad8_count_preset_enable_read(struct counte= r_device *counter, struct counter_count *count, u8 *preset_enable) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); =20 *preset_enable =3D !priv->preset_enable[count->id]; =20 @@ -818,7 +823,7 @@ static int quad8_count_preset_enable_write(struct count= er_device *counter, struct counter_count *count, u8 preset_enable) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const int base_offset =3D priv->base + 2 * count->id + 1; unsigned long irqflags; unsigned int ior_cfg; @@ -845,7 +850,7 @@ static int quad8_signal_cable_fault_read(struct counter= _device *counter, struct counter_signal *signal, u8 *cable_fault) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id / 2; unsigned long irqflags; bool disabled; @@ -875,7 +880,7 @@ static int quad8_signal_cable_fault_enable_read(struct = counter_device *counter, struct counter_signal *signal, u8 *enable) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id / 2; =20 *enable =3D !!(priv->cable_fault_enable & BIT(channel_id)); @@ -887,7 +892,7 @@ static int quad8_signal_cable_fault_enable_write(struct= counter_device *counter, struct counter_signal *signal, u8 enable) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id / 2; unsigned long irqflags; unsigned int cable_fault_enable; @@ -913,7 +918,7 @@ static int quad8_signal_fck_prescaler_read(struct count= er_device *counter, struct counter_signal *signal, u8 *prescaler) { - const struct quad8 *const priv =3D counter->priv; + const struct quad8 *const priv =3D quad8_from_counter(counter); =20 *prescaler =3D priv->fck_prescaler[signal->id / 2]; =20 @@ -924,7 +929,7 @@ static int quad8_signal_fck_prescaler_write(struct coun= ter_device *counter, struct counter_signal *signal, u8 prescaler) { - struct quad8 *const priv =3D counter->priv; + struct quad8 *const priv =3D quad8_from_counter(counter); const size_t channel_id =3D signal->id / 2; const int base_offset =3D priv->base + 2 * channel_id; unsigned long irqflags; @@ -1150,7 +1155,6 @@ static int quad8_probe(struct device *dev, unsigned i= nt id) priv->counter.num_counts =3D ARRAY_SIZE(quad8_counts); priv->counter.signals =3D quad8_signals; priv->counter.num_signals =3D ARRAY_SIZE(quad8_signals); - priv->counter.priv =3D priv; priv->base =3D base[id]; =20 spin_lock_init(&priv->lock); --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 902F0C43217 for ; Tue, 21 Dec 2021 10:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbhLUKqI (ORCPT ); Tue, 21 Dec 2021 05:46:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233864AbhLUKqH (ORCPT ); Tue, 21 Dec 2021 05:46:07 -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 DDCA6C061401 for ; Tue, 21 Dec 2021 02:46:06 -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 1mzcei-0005BB-O7; Tue, 21 Dec 2021 11:46:04 +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 1mzcei-005nfv-0Z; Tue, 21 Dec 2021 11:46:03 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceg-0004BV-Qw; Tue, 21 Dec 2021 11:46:02 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Patrick Havelange , William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] counter: ftm-quaddec: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:40 +0100 Message-Id: <20211221104546.214066-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=BLGgbKMWZQKSAyjRUdMvXiPE7PeMpJ6W8Y/gNVLaPbQ=; m=aj1hUrB8DlH//87Ydw8Bemkjf0cLnFHRoYJEeeBnUfI=; p=O6E+g1NOkcrJHwxshcrDT/kwLeZH9H/HJ0p6iqUb3Zc=; g=ba193b2403a26e3f2c830b4207aeb7b8d7652685 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsDIACgkQwfwUeK3K7AkjFwf/Z+s aPbKKu9y3QG6gzgKXVIXvCg/YvmgmrA/o+IEmMp7m1FyxUs2CVJ83/JQ1jNGZB6bjfHnT+5OzgzEU fKAoYdEbdIWQlHuXfxYv9Xa5FrvvKuvLzdSRqm1IPf7WM+gIeufwqBz4yykKHTwmOsgGOUJpdAMR8 v04MLAH41tkEfFJztxZFOYmVdQAqftuT1KOXc+Tek2tZwIuiecp6YKNhdVA05iCTVzxBb89vaLEvf uHCfovZ1yzhSJDVBx+jp3Ao0vGfJM41QVkn0Hqltdp+Qf51jBlqo4woG1ju5FRfp38VD2vRuReg7n v5get7KQuA9luvgKhF1qJSc834iyAgg== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. (In this case even a noop because the offset is 0.) So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-60 (-60) Function old new delta ftm_quaddec_set_prescaler 612 600 -12 ftm_quaddec_probe 596 584 -12 ftm_quaddec_get_prescaler 156 144 -12 ftm_quaddec_count_write 232 220 -12 ftm_quaddec_count_read 152 140 -12 Total: Before=3D5096, After=3D5036, chg -1.18% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/ftm-quaddec.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index 5ef0478709cd..b58a4f54e97b 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -33,6 +33,11 @@ struct ftm_quaddec { struct mutex ftm_quaddec_mutex; }; =20 +static inline struct ftm_quaddec *ftm_from_counter(struct counter_device *= counter) +{ + return container_of(counter, struct ftm_quaddec, counter); +} + static void ftm_read(struct ftm_quaddec *ftm, uint32_t offset, uint32_t *d= ata) { if (ftm->big_endian) @@ -118,7 +123,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 =3D counter->priv; + struct ftm_quaddec *ftm =3D ftm_from_counter(counter); uint32_t scflags; =20 ftm_read(ftm, FTM_SC, &scflags); @@ -131,7 +136,7 @@ static int ftm_quaddec_get_prescaler(struct counter_dev= ice *counter, static int ftm_quaddec_set_prescaler(struct counter_device *counter, struct counter_count *count, u32 cnt_mode) { - struct ftm_quaddec *ftm =3D counter->priv; + struct ftm_quaddec *ftm =3D ftm_from_counter(counter); =20 mutex_lock(&ftm->ftm_quaddec_mutex); =20 @@ -162,7 +167,7 @@ static int ftm_quaddec_count_read(struct counter_device= *counter, struct counter_count *count, u64 *val) { - struct ftm_quaddec *const ftm =3D counter->priv; + struct ftm_quaddec *const ftm =3D ftm_from_counter(counter); uint32_t cntval; =20 ftm_read(ftm, FTM_CNT, &cntval); @@ -176,7 +181,7 @@ static int ftm_quaddec_count_write(struct counter_devic= e *counter, struct counter_count *count, const u64 val) { - struct ftm_quaddec *const ftm =3D counter->priv; + struct ftm_quaddec *const ftm =3D ftm_from_counter(counter); =20 if (val !=3D 0) { dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n"); @@ -292,7 +297,6 @@ static int ftm_quaddec_probe(struct platform_device *pd= ev) ftm->counter.num_counts =3D 1; ftm->counter.signals =3D ftm_quaddec_signals; ftm->counter.num_signals =3D ARRAY_SIZE(ftm_quaddec_signals); - ftm->counter.priv =3D ftm; =20 mutex_init(&ftm->ftm_quaddec_mutex); =20 --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 880AFC433EF for ; Tue, 21 Dec 2021 10:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235841AbhLUKqQ (ORCPT ); Tue, 21 Dec 2021 05:46:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234110AbhLUKqJ (ORCPT ); Tue, 21 Dec 2021 05:46:09 -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 B4A55C061574 for ; Tue, 21 Dec 2021 02:46:08 -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 1mzcei-0005BD-O6; Tue, 21 Dec 2021 11:46:04 +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 1mzcei-005nfy-5M; Tue, 21 Dec 2021 11:46:03 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceh-0004Bv-0I; Tue, 21 Dec 2021 11:46:03 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Jarkko Nikula , William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] counter: intel-qeb: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:41 +0100 Message-Id: <20211221104546.214066-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=ThNGokgiWcn75qYGbTuomR6f88obJKYrRrSmNBoFD5I=; m=Hg8zE/asUx2g3czk+o5m3SY3gEaouSs/V53jAvhKGzw=; p=ZyUJpfCbrjrA8N6THSfxjmBhtCsfDdq6XEd4Xr1NFZY=; g=e137413badb1a0c1fd78f5213f3b717e8703a1de X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsDUACgkQwfwUeK3K7AlL7wf/d79 RnEH3XmALXk6BQ5vAaTzhNTWG9S/+v5u9NKZvF9p+zGAg5OCE5es/tbqueYNC5IiV0mbUJRoU3POK 3Hi/PZGnQVT5OnJVg39at/9kzUEaK5VEwI/WV+oUn56wLKROysBrpOd9POQLN/H1+P9Y3qpZW9SU5 TSNdHHTUXiLnTLHnvPUiAaSwE9ABPFuDueHHb33qoV/PPL62D3rJiyrxQbiqHT0WLLVzfcOfvEca7 5NPmgmMKTkCQhgt1j2yLGWd2qIrFf++rVZNzsX3//MqRyNNAf9k0cYQm8OVS0MWQiokP+Pw9aNhjk wN6CIs/TJsP6c5l6xd9V3Yn84Euv55g== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. (In this case even a noop because the offset is 0.) So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 0/10 up/down: 0/-116 (-116) Function old new delta intel_qep_spike_filter_ns_write 552 544 -8 intel_qep_spike_filter_ns_read 252 240 -12 intel_qep_probe 692 680 -12 intel_qep_preset_enable_write 276 264 -12 intel_qep_preset_enable_read 164 152 -12 intel_qep_enable_write 500 488 -12 intel_qep_enable_read 80 68 -12 intel_qep_count_read 140 128 -12 intel_qep_ceiling_write 260 248 -12 intel_qep_ceiling_read 140 128 -12 Total: Before=3D4867, After=3D4751, chg -2.38% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/intel-qep.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index 0924d16de6e2..168f8f5357cf 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -74,6 +74,11 @@ struct intel_qep { u32 qepmax; }; =20 +static inline struct intel_qep *intel_qep_from_counter(struct counter_devi= ce *counter) +{ + return container_of(counter, struct intel_qep, counter); +} + static inline u32 intel_qep_readl(struct intel_qep *qep, u32 offset) { return readl(qep->regs + offset); @@ -109,7 +114,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 =3D counter->priv; + struct intel_qep *const qep =3D intel_qep_from_counter(counter); =20 pm_runtime_get_sync(qep->dev); *val =3D intel_qep_readl(qep, INTEL_QEPCOUNT); @@ -176,7 +181,7 @@ static struct counter_synapse intel_qep_count_synapses[= ] =3D { static int intel_qep_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct intel_qep *qep =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); =20 pm_runtime_get_sync(qep->dev); *ceiling =3D intel_qep_readl(qep, INTEL_QEPMAX); @@ -188,7 +193,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 =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); int ret =3D 0; =20 /* Intel QEP ceiling configuration only supports 32-bit values */ @@ -213,7 +218,7 @@ static int intel_qep_ceiling_write(struct counter_devic= e *counter, static int intel_qep_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct intel_qep *qep =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); =20 *enable =3D qep->enabled; =20 @@ -223,7 +228,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 =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); u32 reg; bool changed; =20 @@ -256,7 +261,7 @@ static int intel_qep_spike_filter_ns_read(struct counte= r_device *counter, struct counter_count *count, u64 *length) { - struct intel_qep *qep =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); u32 reg; =20 pm_runtime_get_sync(qep->dev); @@ -277,7 +282,7 @@ static int intel_qep_spike_filter_ns_write(struct count= er_device *counter, struct counter_count *count, u64 length) { - struct intel_qep *qep =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); u32 reg; bool enable; int ret =3D 0; @@ -326,7 +331,7 @@ static int intel_qep_preset_enable_read(struct counter_= device *counter, struct counter_count *count, u8 *preset_enable) { - struct intel_qep *qep =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); u32 reg; =20 pm_runtime_get_sync(qep->dev); @@ -341,7 +346,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 =3D counter->priv; + struct intel_qep *qep =3D intel_qep_from_counter(counter); u32 reg; int ret =3D 0; =20 @@ -429,7 +434,6 @@ static int intel_qep_probe(struct pci_dev *pci, const s= truct pci_device_id *id) qep->counter.num_counts =3D ARRAY_SIZE(intel_qep_counter_count); qep->counter.signals =3D intel_qep_signals; qep->counter.num_signals =3D ARRAY_SIZE(intel_qep_signals); - qep->counter.priv =3D qep; qep->enabled =3D false; =20 pm_runtime_put(dev); --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 25DBEC433FE for ; Tue, 21 Dec 2021 10:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234126AbhLUKqJ (ORCPT ); Tue, 21 Dec 2021 05:46:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbhLUKqH (ORCPT ); Tue, 21 Dec 2021 05:46:07 -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 14BE3C061748 for ; Tue, 21 Dec 2021 02:46:07 -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 1mzcei-0005BI-Rb; Tue, 21 Dec 2021 11:46:04 +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 1mzcei-005nfz-FY; Tue, 21 Dec 2021 11:46:03 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceh-0004By-7D; Tue, 21 Dec 2021 11:46:03 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Oleksij Rempel , William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] counter: interrupt-cnt: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:42 +0100 Message-Id: <20211221104546.214066-5-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=k5h2hlgCdmOIAEJ7Fs8WZpknSGjaIvXaLZnK8BkIGW8=; m=zhLK+hnhOwzuTQYiqBPMLfjqowx6F6J8r6X6vgVOca8=; p=dgCJ1NZDgXSaEGIddQpEUHjgk268Zy+G9OFdHZSQSG4=; g=4e97fb2e9cadb1143a60b137d87eabb130b8e4f4 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsD8ACgkQwfwUeK3K7Anx7Qf9GyT QCjMD2VJKD3SdfZOlrlbJf/rli/UpGwRJkMP4tTH1cyuWTC8A/I+wvsw8YBzj42OwRV+RmRfXw38J 6ak+MZ8isF7Djt7rvwVeasI142MpP9teM45mSHNhdaXNR0GmXSk6W8qVxDGKkUYLJciXz5un1YYUd 0WhlSgP0NZeJJC3uIxNuesd1d7GWUZV6DUXWGzpuMkpHVKt0MDLWhtxNecapeN52+4CTb4fDblRRS 2Gb0m7Rmp30Kt2qPiDXGtVTiEUg7P+BwzmoiHetE2BUReKCV006pGtTAwR8LvPLJyc5qIpSaUYGaK IVpKuKSUaS091DeJTFuuUcmbnB9f+qQ== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-60 (-60) Function old new delta interrupt_cnt_write 136 128 -8 interrupt_cnt_read 92 84 -8 interrupt_cnt_enable_write 180 172 -8 interrupt_cnt_enable_read 76 68 -8 interrupt_cnt_probe 1048 1036 -12 interrupt_cnt_signal_read 164 148 -16 Total: Before=3D2841, After=3D2781, chg -2.11% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/interrupt-cnt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cn= t.c index 8514a87fcbee..c61628aa5c32 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -25,6 +25,11 @@ struct interrupt_cnt_priv { struct counter_count cnts; }; =20 +static inline struct interrupt_cnt_priv *interrupt_cnt_from_counter(struct= counter_device *counter) +{ + return container_of(counter, struct interrupt_cnt_priv, counter); +} + static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id) { struct interrupt_cnt_priv *priv =3D dev_id; @@ -37,7 +42,7 @@ static irqreturn_t interrupt_cnt_isr(int irq, void *dev_i= d) static int interrupt_cnt_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct interrupt_cnt_priv *priv =3D counter->priv; + struct interrupt_cnt_priv *priv =3D interrupt_cnt_from_counter(counter); =20 *enable =3D priv->enabled; =20 @@ -47,7 +52,7 @@ static int interrupt_cnt_enable_read(struct counter_devic= e *counter, static int interrupt_cnt_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct interrupt_cnt_priv *priv =3D counter->priv; + struct interrupt_cnt_priv *priv =3D interrupt_cnt_from_counter(counter); =20 if (priv->enabled =3D=3D enable) return 0; @@ -85,7 +90,7 @@ static int interrupt_cnt_action_read(struct counter_devic= e *counter, static int interrupt_cnt_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct interrupt_cnt_priv *priv =3D counter->priv; + struct interrupt_cnt_priv *priv =3D interrupt_cnt_from_counter(counter); =20 *val =3D atomic_read(&priv->count); =20 @@ -95,7 +100,7 @@ static int interrupt_cnt_read(struct counter_device *cou= nter, static int interrupt_cnt_write(struct counter_device *counter, struct counter_count *count, const u64 val) { - struct interrupt_cnt_priv *priv =3D counter->priv; + struct interrupt_cnt_priv *priv =3D interrupt_cnt_from_counter(counter); =20 if (val !=3D (typeof(priv->count.counter))val) return -ERANGE; @@ -122,7 +127,7 @@ static int interrupt_cnt_signal_read(struct counter_dev= ice *counter, struct counter_signal *signal, enum counter_signal_level *level) { - struct interrupt_cnt_priv *priv =3D counter->priv; + struct interrupt_cnt_priv *priv =3D interrupt_cnt_from_counter(counter); int ret; =20 if (!priv->gpio) @@ -199,7 +204,6 @@ static int interrupt_cnt_probe(struct platform_device *= pdev) priv->cnts.ext =3D interrupt_cnt_ext; priv->cnts.num_ext =3D ARRAY_SIZE(interrupt_cnt_ext); =20 - priv->counter.priv =3D priv; priv->counter.name =3D dev_name(dev); priv->counter.parent =3D dev; priv->counter.ops =3D &interrupt_cnt_ops; --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 E2AC2C433F5 for ; Tue, 21 Dec 2021 10:46:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234854AbhLUKqO (ORCPT ); Tue, 21 Dec 2021 05:46:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234121AbhLUKqJ (ORCPT ); Tue, 21 Dec 2021 05:46:09 -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 D25EFC06173F for ; Tue, 21 Dec 2021 02:46:08 -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 1mzcei-0005BH-O6; Tue, 21 Dec 2021 11:46:04 +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 1mzcei-005ng2-F6; Tue, 21 Dec 2021 11:46:03 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceh-0004C6-DM; Tue, 21 Dec 2021 11:46:03 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Kamel Bouhara , William Breathitt Gray Cc: linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] counter: microchip-tcp-capture: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:43 +0100 Message-Id: <20211221104546.214066-6-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=+mGMCzcHVB52IvHhf9leKp6Y9DlWvz9ld0t8InuL0Q4=; m=m4jRnAmJlhgb59M+JVnjEsk6IMQPqWL9MFo6aBi4ZGA=; p=AXyjvzc03RwiiDbH4rGJn2dLLt6SLlipHOAxCyxAePg=; g=0118e46f757cd59c8cf911fec853a5b5c7162064 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsEIACgkQwfwUeK3K7AkrRAgAn5X rbIhFZqaAclK48bgp/jaTqoNE3hvRtJDGKyKqMCNUIFt394aZZ0H9VmwtJYsOD2eGk0csSWcqpJUK uNmPXRTbJMzwtvx4CEbleKsmcfTRQmQGbaSVL/4Zalh5vIQYcsjBp1ZHnV0YKBaVpoDMaUWxnAUBs EH3RWdkpc0qI8eCJJBeo2a5RjdbCgePbFurA8tkV7J3PX/cQWXpOOk7pstJyISzDtbmHaWWM7mj9f fgrMaZrTemxCV0HgyCn0AGZA3JAJ5lOvCdTn9dRdl1MZay7ZkFP+9DYaiMKXlIU/9tanMqzPu63s3 x/71Ax7/ii/XmTowtkYyseMrhpFVVHA== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 1/6 up/down: 12/-68 (-56) Function old new delta mchp_tc_count_function_write 1016 1028 +12 mchp_tc_count_action_write 204 196 -8 mchp_tc_probe 1376 1364 -12 mchp_tc_count_signal_read 360 348 -12 mchp_tc_count_read 264 252 -12 mchp_tc_count_function_read 108 96 -12 mchp_tc_count_action_read 392 380 -12 Total: Before=3D5920, After=3D5864, chg -0.95% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/microchip-tcb-capture.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/micr= ochip-tcb-capture.c index 0ab1b2716784..031e79f5f06a 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -32,6 +32,11 @@ struct mchp_tc_data { bool trig_inverted; }; =20 +static inline struct mchp_tc_data *mchp_tc_from_counter(struct counter_dev= ice *counter) +{ + return container_of(counter, struct mchp_tc_data, counter); +} + static const enum counter_function mchp_tc_count_functions[] =3D { COUNTER_FUNCTION_INCREASE, COUNTER_FUNCTION_QUADRATURE_X4, @@ -72,7 +77,7 @@ static int mchp_tc_count_function_read(struct counter_dev= ice *counter, struct counter_count *count, enum counter_function *function) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); =20 if (priv->qdec_mode) *function =3D COUNTER_FUNCTION_QUADRATURE_X4; @@ -86,7 +91,7 @@ static int mchp_tc_count_function_write(struct counter_de= vice *counter, struct counter_count *count, enum counter_function function) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); u32 bmr, cmr; =20 regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr); @@ -148,7 +153,7 @@ static int mchp_tc_count_signal_read(struct counter_dev= ice *counter, struct counter_signal *signal, enum counter_signal_level *lvl) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); bool sigstatus; u32 sr; =20 @@ -169,7 +174,7 @@ static int mchp_tc_count_action_read(struct counter_dev= ice *counter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); u32 cmr; =20 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); @@ -197,7 +202,7 @@ static int mchp_tc_count_action_write(struct counter_de= vice *counter, struct counter_synapse *synapse, enum counter_synapse_action action) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); u32 edge =3D ATMEL_TC_ETRGEDG_NONE; =20 /* QDEC mode is rising edge only */ @@ -230,7 +235,7 @@ static int mchp_tc_count_action_write(struct counter_de= vice *counter, static int mchp_tc_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct mchp_tc_data *const priv =3D counter->priv; + struct mchp_tc_data *const priv =3D mchp_tc_from_counter(counter); u32 cnt; =20 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt); @@ -369,7 +374,6 @@ static int mchp_tc_probe(struct platform_device *pdev) priv->counter.counts =3D mchp_tc_counts; priv->counter.num_signals =3D ARRAY_SIZE(mchp_tc_count_signals); priv->counter.signals =3D mchp_tc_count_signals; - priv->counter.priv =3D priv; =20 return devm_counter_register(&pdev->dev, &priv->counter); } --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 E0C4CC433FE for ; Tue, 21 Dec 2021 10:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236758AbhLUKqS (ORCPT ); Tue, 21 Dec 2021 05:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234841AbhLUKqO (ORCPT ); Tue, 21 Dec 2021 05:46:14 -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 C5512C06173F for ; Tue, 21 Dec 2021 02:46:13 -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 1mzcel-0005BN-V1; Tue, 21 Dec 2021 11:46:08 +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 1mzcei-005ng5-TZ; Tue, 21 Dec 2021 11:46:04 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceh-0004CE-JM; Tue, 21 Dec 2021 11:46:03 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Fabrice Gasnier , William Breathitt Gray , Maxime Coquelin , Alexandre Torgue Cc: linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] counter: stm32-lptimer-cnt: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:44 +0100 Message-Id: <20211221104546.214066-7-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=1HOXp2/duyo6n/2D4QQ5RE3nJbn3xI4q4e0n+QcZL4o=; m=kIc7VsSS0WRvJXcgL7haggwSGZnZfnb/5UpfyeNoh+I=; p=bQvWuGWMnZ1NXlmcBpZTTro6PdXlihtuS79lnHsi8WA=; g=b00ec8495b7403537c3bc26005bb71ad27f8b411 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsEYACgkQwfwUeK3K7AkBRgf+I3T 09U/qrDBmUGLwlot6PnfpTnrDpXaZeHRO29u5clIrtVMauKmCzqEWxoIBCHse9BiJU9MZcnBNS5Qk sDFXPjn8IrKwIoTloWjEIzyzIF6x4MjX6n6w+NbeC2apl2vMKiYmOMJLF08vO9yfReXQVcnY9quhy HMDCm+xeFAt6h2axCGg7Og4arWLAXJrsdooewiS4ZdK1wHkWt6x9+rdO6x9sKhCndefH2vq/QEi5h CLrlHoTzc/mkUoC28ifXGCRyRIKUIOlLdwvKwmpKd3X3SFsUR8kNM+IXVa1chI9N+skNPsoezw0xJ XGp7KYwWM0A0EuB3rXXnHYQaeaJKeew== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. (In this case even a noop because the offset is 0.) So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 0/10 up/down: 0/-140 (-140) Function old new delta stm32_lptim_cnt_read 272 260 -12 stm32_lptim_cnt_probe 528 516 -12 stm32_lptim_cnt_function_write 420 408 -12 stm32_lptim_cnt_function_read 184 172 -12 stm32_lptim_cnt_enable_write 436 424 -12 stm32_lptim_cnt_enable_read 312 300 -12 stm32_lptim_cnt_ceiling_write 368 356 -12 stm32_lptim_cnt_ceiling_read 84 72 -12 stm32_lptim_cnt_action_read 388 376 -12 stm32_lptim_cnt_action_write 576 544 -32 Total: Before=3D6458, After=3D6318, chg -2.17% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/stm32-lptimer-cnt.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lp= timer-cnt.c index 5168833b1fdf..c6eb3071571f 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -30,6 +30,11 @@ struct stm32_lptim_cnt { bool enabled; }; =20 +static inline struct stm32_lptim_cnt *stm32_lptim_from_counter(struct coun= ter_device *counter) +{ + return container_of(counter, struct stm32_lptim_cnt, counter); +} + static int stm32_lptim_is_enabled(struct stm32_lptim_cnt *priv) { u32 val; @@ -141,7 +146,7 @@ static const enum counter_synapse_action stm32_lptim_cn= t_synapse_actions[] =3D { static int stm32_lptim_cnt_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); u32 cnt; int ret; =20 @@ -158,7 +163,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 =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); =20 if (!priv->quadrature_mode) { *function =3D COUNTER_FUNCTION_INCREASE; @@ -177,7 +182,7 @@ static int stm32_lptim_cnt_function_write(struct counte= r_device *counter, struct counter_count *count, enum counter_function function) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); =20 if (stm32_lptim_is_enabled(priv)) return -EBUSY; @@ -200,7 +205,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_d= evice *counter, struct counter_count *count, u8 *enable) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); int ret; =20 ret =3D stm32_lptim_is_enabled(priv); @@ -216,7 +221,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_= device *counter, struct counter_count *count, u8 enable) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); int ret; =20 /* Check nobody uses the timer, or already disabled/enabled */ @@ -241,7 +246,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_= device *counter, struct counter_count *count, u64 *ceiling) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); =20 *ceiling =3D priv->ceiling; =20 @@ -252,7 +257,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter= _device *counter, struct counter_count *count, u64 ceiling) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); =20 if (stm32_lptim_is_enabled(priv)) return -EBUSY; @@ -277,7 +282,7 @@ static int stm32_lptim_cnt_action_read(struct counter_d= evice *counter, struct counter_synapse *synapse, enum counter_synapse_action *action) { - struct stm32_lptim_cnt *const priv =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); enum counter_function function; int err; =20 @@ -321,7 +326,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 =3D counter->priv; + struct stm32_lptim_cnt *const priv =3D stm32_lptim_from_counter(counter); enum counter_function function; int err; =20 @@ -438,7 +443,6 @@ static int stm32_lptim_cnt_probe(struct platform_device= *pdev) } priv->counter.num_counts =3D 1; priv->counter.signals =3D stm32_lptim_cnt_signals; - priv->counter.priv =3D priv; =20 platform_set_drvdata(pdev, priv); =20 --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 6F3B5C4332F for ; Tue, 21 Dec 2021 10:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234051AbhLUKqU (ORCPT ); Tue, 21 Dec 2021 05:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234647AbhLUKqN (ORCPT ); Tue, 21 Dec 2021 05:46:13 -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 7CCDCC061574 for ; Tue, 21 Dec 2021 02:46:13 -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 1mzcel-0005BM-V2; Tue, 21 Dec 2021 11:46:08 +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 1mzcei-005ngA-QG; Tue, 21 Dec 2021 11:46:04 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzceh-0004CS-Ru; Tue, 21 Dec 2021 11:46:03 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Fabrice Gasnier , William Breathitt Gray , Maxime Coquelin , Alexandre Torgue Cc: linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] counter: stm32-timer-cnt: Use container_of instead of struct counter_device::priv Date: Tue, 21 Dec 2021 11:45:45 +0100 Message-Id: <20211221104546.214066-8-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=1Puab3XzxTVHN4jt651Xcm2ayt/NNTv3C4elozlzC2c=; m=/5nCYZ7WihDc/POXwyjyGoYCMmam3kFfXztb+Karnfk=; p=PcKDfqcYgcbKTwKZqW51cpBm6Qds+AfbyFYCjb3Ofbk=; g=1bfafced00b53cbf6f10ae27a2268b0e8968d011 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsEkACgkQwfwUeK3K7AmJKwgAmBL 8/QWoB+RYTBqLn7TQTv6QsEBT9f2ye7dhiiWn9EX0va0ygaWeyG0bvdx+3cFihsja5F6Xzt8FdlAf 3DSfrMwWSSvOfTDO+lXWfJySxktxhth1UX/XtB8S+FMQb7zBHlb1nM2VN0m7aeuuRMKCRgH/EchME 5Ch019QIQIIhpr7uPok7oBKDH59361kH76T69Zszld/dLkb4mLs94FrvaptA8kKjzzn14iwQcc3x3 OAhyXy7yYBY3xXyPZHF+Ldxe6qpPprHAQHIW72hU/qgYI0feQZdKSpN8ViJi9X2qheDRwagfCv8Kr tcqlsn9HP/pltFBp00WXKVN+z7o2q5Q== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using counter->priv is a memory read and so more expensive than container_of which is only an addition. (In this case even a noop because the offset is 0.) So container_of is expected to be a tad faster, it's type-safe, and produces smaller code (ARCH=3Darm allmodconfig): add/remove: 0/0 grow/shrink: 0/11 up/down: 0/-132 (-132) Function old new delta stm32_timer_cnt_probe 436 424 -12 stm32_count_write 312 300 -12 stm32_count_read 236 224 -12 stm32_count_function_write 492 480 -12 stm32_count_function_read 396 384 -12 stm32_count_enable_write 488 476 -12 stm32_count_enable_read 236 224 -12 stm32_count_direction_read 240 228 -12 stm32_count_ceiling_write 200 188 -12 stm32_count_ceiling_read 236 224 -12 stm32_action_read 492 480 -12 Total: Before=3D5504, After=3D5372, chg -2.40% Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/stm32-timer-cnt.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-time= r-cnt.c index 0546e932db0c..ac0bea6ce690 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -37,6 +37,11 @@ struct stm32_timer_cnt { struct stm32_timer_regs bak; }; =20 +static inline struct stm32_timer_cnt *stm32_count_from_counter(struct coun= ter_device *counter) +{ + return container_of(counter, struct stm32_timer_cnt, counter); +} + static const enum counter_function stm32_count_functions[] =3D { COUNTER_FUNCTION_INCREASE, COUNTER_FUNCTION_QUADRATURE_X2_A, @@ -47,7 +52,7 @@ static const enum counter_function stm32_count_functions[= ] =3D { static int stm32_count_read(struct counter_device *counter, struct counter_count *count, u64 *val) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 cnt; =20 regmap_read(priv->regmap, TIM_CNT, &cnt); @@ -59,7 +64,7 @@ static int stm32_count_read(struct counter_device *counte= r, static int stm32_count_write(struct counter_device *counter, struct counter_count *count, const u64 val) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 ceiling; =20 regmap_read(priv->regmap, TIM_ARR, &ceiling); @@ -73,7 +78,7 @@ static int stm32_count_function_read(struct counter_devic= e *counter, struct counter_count *count, enum counter_function *function) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 smcr; =20 regmap_read(priv->regmap, TIM_SMCR, &smcr); @@ -100,7 +105,7 @@ static int stm32_count_function_write(struct counter_de= vice *counter, struct counter_count *count, enum counter_function function) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 cr1, sms; =20 switch (function) { @@ -140,7 +145,7 @@ static int stm32_count_direction_read(struct counter_de= vice *counter, struct counter_count *count, enum counter_count_direction *direction) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 cr1; =20 regmap_read(priv->regmap, TIM_CR1, &cr1); @@ -153,7 +158,7 @@ static int stm32_count_direction_read(struct counter_de= vice *counter, static int stm32_count_ceiling_read(struct counter_device *counter, struct counter_count *count, u64 *ceiling) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 arr; =20 regmap_read(priv->regmap, TIM_ARR, &arr); @@ -166,7 +171,7 @@ static int stm32_count_ceiling_read(struct counter_devi= ce *counter, static int stm32_count_ceiling_write(struct counter_device *counter, struct counter_count *count, u64 ceiling) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); =20 if (ceiling > priv->max_arr) return -ERANGE; @@ -181,7 +186,7 @@ static int stm32_count_ceiling_write(struct counter_dev= ice *counter, static int stm32_count_enable_read(struct counter_device *counter, struct counter_count *count, u8 *enable) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 cr1; =20 regmap_read(priv->regmap, TIM_CR1, &cr1); @@ -194,7 +199,7 @@ static int stm32_count_enable_read(struct counter_devic= e *counter, static int stm32_count_enable_write(struct counter_device *counter, struct counter_count *count, u8 enable) { - struct stm32_timer_cnt *const priv =3D counter->priv; + struct stm32_timer_cnt *const priv =3D stm32_count_from_counter(counter); u32 cr1; =20 if (enable) { @@ -336,7 +341,6 @@ static int stm32_timer_cnt_probe(struct platform_device= *pdev) priv->counter.num_counts =3D 1; priv->counter.signals =3D stm32_signals; priv->counter.num_signals =3D ARRAY_SIZE(stm32_signals); - priv->counter.priv =3D priv; =20 platform_set_drvdata(pdev, priv); =20 --=20 2.33.0 From nobody Wed Jul 1 13:29:19 2026 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 4DDBAC433EF for ; Tue, 21 Dec 2021 10:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234376AbhLUKqM (ORCPT ); Tue, 21 Dec 2021 05:46:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234113AbhLUKqJ (ORCPT ); Tue, 21 Dec 2021 05:46:09 -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 D6A8DC061401 for ; Tue, 21 Dec 2021 02:46:08 -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 1mzcej-0005BQ-7b; Tue, 21 Dec 2021 11:46:05 +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 1mzcej-005ngB-6A; Tue, 21 Dec 2021 11:46:04 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mzcei-0004CY-1b; Tue, 21 Dec 2021 11:46:04 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: David Lechner , William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] counter: Remove unused member from struct counter_device Date: Tue, 21 Dec 2021 11:45:46 +0100 Message-Id: <20211221104546.214066-9-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> References: <20211221104546.214066-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Patch-Hashes: v=1; h=sha256; i=Y0NkBLHZbTPV9AgKvEXqVQXBuc1J1Y5wZlZqUt+q8z8=; m=gRJhxNFIrXvCs2HMMhrXRYXJ62P50jhM9VxuUIFr16M=; p=2zqxcELaKv036XA4cqHni0/9tKYCfObbbaJb80+Waf0=; g=66d467d4dda659dec3678c8363304f55cb46ce85 X-Patch-Sig: m=pgp; i=u.kleine-koenig@pengutronix.de; s=0x0D2511F322BFAB1C1580266BE2DCDD9132669BD6; b=iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAmHBsFIACgkQwfwUeK3K7Ak4BQf+Jab Qe3ZLW5+lF0d5ZR9GNedPSuZVa54hNR9n8KeVlE68fdhXjdDB5V+GKDNjN2do9Zh6pvDkqoVgT5cd yLjSIUdDnzshi304AduYuD+kPig8lWozhUwR4IlJ4OG/tvaNh0iW2UUbbRszBC1lsTb08f0bvL+1/ bDAw4xafTThYVlUWQ2x1JTQfBsd9tvbabkYewGmjzSN0G/pTa9Q9P/+5sNpMmEARWF30P6YDLgqT1 zB3FWl3pyLO7qj+bz7f5FlF7rYMre+LN/BH4doMfx5Im39EVXtWvOiz6Z2rLKxGV6xnnskwI+TxVb E65U+vojgrFIiq8EyLeds4XPrE7Il0Q== Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The functionality priv was designed for can better be accomplished using container_of. All drivers have been converted, so drop this now unused member. Just one assignment was missed in the conversion of the ti-eqep driver. This is unused and so can be safely dropped, too. Signed-off-by: Uwe Kleine-K=C3=B6nig --- drivers/counter/ti-eqep.c | 1 - include/linux/counter.h | 3 --- 2 files changed, 4 deletions(-) diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index 9e0e46bca4c2..8cdc9ab98859 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -402,7 +402,6 @@ static int ti_eqep_probe(struct platform_device *pdev) priv->counter.num_counts =3D ARRAY_SIZE(ti_eqep_counts); priv->counter.signals =3D ti_eqep_signals; priv->counter.num_signals =3D ARRAY_SIZE(ti_eqep_signals); - priv->counter.priv =3D priv; =20 platform_set_drvdata(pdev, priv); =20 diff --git a/include/linux/counter.h b/include/linux/counter.h index b7d0a00a61cf..fd58f36ea2f7 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -287,7 +287,6 @@ struct counter_ops { * @num_counts: number of Counts specified in @counts * @ext: optional array of Counter device extensions * @num_ext: number of Counter device extensions specified in @ext - * @priv: optional private data supplied by driver * @dev: internal device structure * @chrdev: internal character device structure * @events_list: list of current watching Counter events @@ -314,8 +313,6 @@ struct counter_device { struct counter_comp *ext; size_t num_ext; =20 - void *priv; - struct device dev; struct cdev chrdev; struct list_head events_list; --=20 2.33.0