Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1297593pxa; Sat, 15 Aug 2020 14:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzegf/VkxGnDPnMe2uwi+avy/wfH+mnChwwLw0niMSNDbfB/OwjaxAQHSzdCv5CvVLMJ00 X-Received: by 2002:a17:906:f24c:: with SMTP id gy12mr8286907ejb.275.1597528390659; Sat, 15 Aug 2020 14:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597528390; cv=none; d=google.com; s=arc-20160816; b=HOHyfcFWCrnfuyStScQwQk1WUX98/t3+GB1ypN9PIv7qA23WwDzFPMXNVNx+orXAp6 mAsxM1lyJrhi7MUXeXXMIz4JleC9YC3faS5NnGEVA2fM3/HATHb6VhtW8hy+/50ZdjLn FQHQlSD1yBaKEmLeq+8kC4UVy1EAIQgptxhy5YODm9mKhDi4iwwTNLJo8amsIyiibyLS 0aK1/QE3Di2ztzNHLSp/E+/ZgjER0MPSfj9JKA3iKHwLTt5iIg+QAG832/0oJkcmTmWo ohsZui+9iFo//UM1Ov7xojioyetMk+gEDtgrubXjw5rKrjQiGcHhkx0HY3XwqbxIUJd5 pt4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=UdXi5X9JdCDwyXidCVEz2m+8ZLjKmBUqZLTQciSb2xE=; b=r2KqLXGkq8IggQIk4uJGrGMH7RI5GTSj/fNTzDJdN9LxH2y6Nvzoa2xi8jaZVGOFoH ZO6acI8DaldBpjGHim6VfcHRD31VkMSdVZoLWzH2RfgaRBPj/nHv+1mrCnP3W+8p9MNC SIk6JA+LjVnQmZBV+0oE5RIi44/d2NKelxwKIVmpxSqcYAfNDfIS+kCU2jVTGadKCDI2 dU8qNV7iLrp002n3wJUonucA8ZFhTJVmbW7j4f4PFxHgrmDFiib7OnckBMtQPk0vXX1/ 55yFUP4zc75v4BZT4bq/WVIk/OdxfF3eKbXlzkt5irAMX09dmESbQQVDp2vTJHLr6bEB Hgfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VeyC3/j1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si8619210ejb.647.2020.08.15.14.52.48; Sat, 15 Aug 2020 14:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VeyC3/j1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728919AbgHOVvq (ORCPT + 99 others); Sat, 15 Aug 2020 17:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728694AbgHOVvg (ORCPT ); Sat, 15 Aug 2020 17:51:36 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D600FC0A3BE4; Sat, 15 Aug 2020 09:33:32 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id s16so9283440qtn.7; Sat, 15 Aug 2020 09:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UdXi5X9JdCDwyXidCVEz2m+8ZLjKmBUqZLTQciSb2xE=; b=VeyC3/j14NqkY/CTqvegy+SlcVkPkObQSuCMJPNHGh6GOlJ9veJftRkGQKz6KX0dAg 8GCa9k16hpbcwcrA3S/Iu06iEPUkIza6fv4M4jYFDFr3wvRgAc+EfVs+QcsHLF2xIq0h yvgdHUMc3dZod9aBh4QRs4uXGSAzRUvcOGhtx1xy8mmsQU6cjqKju41+vtxG1uMQYIlX 8r4BVaKyjzM9+gATHvwhVMrKqSXiJg5hybVAHxwOlDcMf2Q5Gh+qqKZGxD2N9HHl95eW 97HJDB8pUBwklrkKvtYRuPYz4uaU9LGil+TeuWihYkvuNVzjhbwV7wVuDBReEwoxdlNu XNGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UdXi5X9JdCDwyXidCVEz2m+8ZLjKmBUqZLTQciSb2xE=; b=HeE1FV3OJNDDcTtE0sDKq9jItHkZ/+VFh+o2nTfsoL9KcaKIdMyHISTVP7BJ+/x4dF bqoQTphNQ29J2d9H/Hxgk5hXv8mCLOLK07O6CkU4Il+8d9dcTdDSEaJySHgIVwDtncb5 XtfszE9Z0LrtegGbB14hkS87HQqZmtQhDoK/JOZ/YEzdnGgYoafjkyDuVcEnABt/P1MZ P46tXHm01iINGXUty46xgKWGyNvW58jei8Y49bxCfg1tdep8etCRv/yz+4CQEyiRvra6 wo+JZHMlBAcLRT5Cv9367n0AapSjX906+NK3XFMwVLf0lSM9XFu7P517kx1jsLargVv0 EsiA== X-Gm-Message-State: AOAM530Yz7Nl9ecIplaHlPeDIlxxK7UpD+iCJo/bgcGGrwhVYsDS/i4Q obPubR5gmjdx8+lIpWcrH0o= X-Received: by 2002:aed:3728:: with SMTP id i37mr6901689qtb.347.1597509209094; Sat, 15 Aug 2020 09:33:29 -0700 (PDT) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id r18sm14063798qtc.90.2020.08.15.09.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2020 09:33:28 -0700 (PDT) Date: Sat, 15 Aug 2020 12:33:11 -0400 From: William Breathitt Gray To: David Lechner Cc: jic23@kernel.org, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, David.Laight@ACULAB.COM Subject: Re: [PATCH v4 1/5] counter: Internalize sysfs interface code Message-ID: <20200815163255.GA6974@shinobu> References: <7209ac3d-d1ca-1b4c-b22c-8d98b13742e2@lechnology.com> <20200802210415.GA606173@shinobu> <4061c9e4-775e-b7a6-14fa-446de4fae537@lechnology.com> <20200809191500.GC6542@shinobu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/NkBOFFp2J2Af1nK" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --/NkBOFFp2J2Af1nK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 10, 2020 at 05:48:07PM -0500, David Lechner wrote: >=20 > >>>>> =20 > >>>>> CPMAC ETHERNET DRIVER > >>>>> M: Florian Fainelli > >>>>> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-qua= d-8.c > >>>>> index 78766b6ec271..0f20920073d6 100644 > >>>>> --- a/drivers/counter/104-quad-8.c > >>>>> +++ b/drivers/counter/104-quad-8.c > >>>>> @@ -621,7 +621,7 @@ static const struct iio_chan_spec quad8_channel= s[] =3D { > >>>>> }; > >>>>> =20 > >>>>> static int quad8_signal_read(struct counter_device *counter, > >>>>> - struct counter_signal *signal, enum counter_signal_value *val) > >>>>> + struct counter_signal *signal, u8 *val) > >>>> > >>>> I'm not a fan of replacing enum types with u8 everywhere in this pat= ch. > >>>> But if we have to for technical reasons (e.g. causes compiler error = if > >>>> we don't) then it would be helpful to add comments giving the enum t= ype > >>>> everywhere like this instance where u8 is actually an enum value. > >>>> > >>>> If we use u32 as the generic type for enums instead of u8, I think t= he > >>>> compiler will happlily let us use enum type and u32 interchangeably = and > >>>> not complain. > >>> > >>> I switched to fixed-width types after the suggestion by David Laight: > >>> https://lkml.org/lkml/2020/5/3/159. I'll CC David Laight just in case= he > >>> wants to chime in again. > >>> > >>> Enum types would be nice for making the valid values explicit, but th= ere > >>> is one benefit I have appreciated from the move to fixed-width types: > >>> there has been a significant reduction of duplicate code; before, we = had > >>> a different read function for each different enum type, but now we us= e a > >>> single function to handle them all. > >> > >> Yes, what I was trying to explain is that by using u32 instead of u8, I > >> think we can actually do both. > >> > >> The function pointers in struct counter_device *counter would use u32 = as a > >> generic enum value in the declaration, but then the actual implementat= ions > >> could still use the proper enum type. > >=20 > > Oh, I see what you mean now. So for example: > >=20 > > int (*signal_read)(struct counter_device *counter, > > struct counter_signal *signal, u8 *val) > >=20 > > This will become instead: > >=20 > > int (*signal_read)(struct counter_device *counter, > > struct counter_signal *signal, u32 *val) > >=20 > > Then in the driver callback implementation we use the enum type we need: > >=20 > > enum counter_signal_level signal_level =3D COUNTER_SIGNAL_HIGH; > > ... > > *val =3D signal_level; > >=20 > > Is that what you have in mind? > >=20 >=20 > Yes. >=20 > Additionally, if we have... >=20 >=20 > int (*x_write)(struct counter_device *counter, > ..., u32 val) > =20 > We should be able to define the implementation as: >=20 > static int my_driver_x_write(struct counter_device *counter, > ..., enum some_type val) > { > ... > } >=20 > Not sure if it works if val is a pointer though. Little- > endian systems would probably be fine, but maybe not big- > endian combined with -fshort-enums compiler flag. >=20 >=20 > int (*x_read)(struct counter_device *counter, > ..., u32 *val) > =20 >=20 > static int my_driver_x_read(struct counter_device *counter, > ..., enum some_type *val) > { > ... > } Regardless of endianness for pointers, will targets that have -fshort-enums enabled by default present a problem here? I imagine that in these cases enum some_type will have a size of unsigned char because that is the first type that can represent all the values: https://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit-f= ields-implementation.html What I'm worried about is whether we can gurantee u32 val can be swapped out with enum some_type val -- or if this is not possible because some architectures will be built with -fshort-enums enabled? William Breathitt Gray --/NkBOFFp2J2Af1nK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl84DkcACgkQhvpINdm7 VJIMkxAAqCR+3cgDGKBMJ0a2SGKYclj8fhdGCxcN4vBaX7BTLdGt9uTejIBoMp4q 1IUyEoXhgzQbwAU19ZXovtu0qVd6YZSYOIPfHcG63QgWClFbsrF1KQVcDryJkdlL mSap7y7MAP8XvawxmUUUQ5hYQYkgT41o1KilQYTcBe4uiyhICTA2ZIl07b1y2ZyC u/ZayKBLY37P2P2T07W6HU3mIIuPTiJEXFzHrrSCB6DnzhtDxzwqbaUAjM6gLpGg aRsUBKnbs7bxO4SiQVq1kFkm9TGRnqwXI0JZq8dZ7UdT49CqkocJKPWvBYsW2hGw Dx8nrlIdN6XOokcHlWhRKXg5SanuqCJqjuHvCM+/PfohLfteT6NOkDkGdUtrS5w5 7KGn5BLGiC1trXIBsZtKThSJNniQC2GXDuTZrqHWgNW6Lb9dGQWAwaHtvv4ngd26 n6f4kfmQGrTf/DQ8B34z3pYxVmPrSYVNYFYwRzGSkoeBc9HGIU+X68RrHnVzQY8N HWsluxVlBD2Zt8vK/+W2sG5gQXr1R2PFXPYsn/dm3zDYWlhqoOK1nGuJXbrwvI8f QBelsICf3bQcObF3kvOFV7QtWS0u36IjjsMunzUVsY6fCHomfsijIFcCmN8ui2mw HBZ7enuTvV7dX0u7yxvce7gRlTuGjEzRXik9kf6p+NsTKpwNgus= =ZYDv -----END PGP SIGNATURE----- --/NkBOFFp2J2Af1nK--