Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4689758pxa; Mon, 10 Aug 2020 15:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiHIQyhiuF5It7uyMSy2J6eiUtkQca/lrH33Oo6ZyEvCAJo/i13eoAuDsvyzjZqt3ZeM4k X-Received: by 2002:a50:ef04:: with SMTP id m4mr23866605eds.63.1597099861406; Mon, 10 Aug 2020 15:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597099861; cv=none; d=google.com; s=arc-20160816; b=ANjXBuhviAZoe26OjbEjZJDfQYO54hvvkTGABmWDZIAqOltUHR/MpGU3coO2fiWooF hJX/RR9LHdry/bgJdUv2ekYKnoWbbqkAbdwaIuoeBv9XlrIy5M5QmWbid+wVwB9sgu/k vBd1It87YATf9zTWRgrrAsR8RaypYGTebqtvqAefv5HmgI8ucvFX4gIBeiuUZ3u/TImr 4USRG3I/ONB/hZe0dYnTemllwDn44qhU9NuM7uOPdznTvjItnqsKgVDKxIJr0qYaKkp0 RRAkHPCXaS+hQhUDn7JyXwx3FBuZ05qNFA10Mkzi5cPq44Zw8vRzZYLFSA9zS6R7lz0H 8J2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=7BO2BV5ZL9NqupaOp8jHyF9nO1ZoO1djC1LGcXRvUvY=; b=doKib6G5kAjZslnDYgBrOG+gUdktKLR2haTrkDCcVmnTqBsXO4mHw7kRGitESBoQmd mYBOajCiJHxT1w8Oh1MgDCTyw2BSuQ2IlfFQM9+lNiY+s9tMQxaU7bei9cuDeF1FzMDj qtB8DHpkehI6lmSzkE3GSHiJDehtEz0dbSwdh/F6e6aVjzCxaU0hwzfgSiv6hYPqAeIs LZ6sH57WQcT9cEQf1JQRrb/ZpvRk+OgRtisV23FF6reBQ8NX/fokBf1qjXruT+Sik+g9 f68YDYp9/mKZeYh+WxwWTtFse/6XjOfISCjl2z/BFaAX3jjonI8wl9wi/cdde1DvsOZ5 I9NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=RaEpa7qT; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si12009717edg.519.2020.08.10.15.50.38; Mon, 10 Aug 2020 15:51:01 -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=fail header.i=@lechnology.com header.s=default header.b=RaEpa7qT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbgHJWsR (ORCPT + 99 others); Mon, 10 Aug 2020 18:48:17 -0400 Received: from vern.gendns.com ([98.142.107.122]:32830 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726775AbgHJWsR (ORCPT ); Mon, 10 Aug 2020 18:48:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7BO2BV5ZL9NqupaOp8jHyF9nO1ZoO1djC1LGcXRvUvY=; b=RaEpa7qTSAHr/gGt2RlO6GMzlB I1P3WYliTKVqcaszmXdUAvTHxtBtLkg6jp5eKrRdsEKwDPrjL0lAeLNLxadiGlaT6J/7fFxaUz2v9 imMr7dGIoiEOPRoGUTDUcciqR6RknkQsq2m7+NxNoPhozDIJmRRlO8Jx5Q/e7Y0+S8JIyrI38z2Kc hKwM3rsrXL+UB5UtCmtCL82UAPgGIk7LddfLH1vH35tXPmhPQOeLDCL8H3NBgoMBIJpcIjtoOQHME HB4mIErsOu2khipwarZw7AP9ShLXPFPm4VCBJijtntN02ZU3z+HGTb74TK25mhke9x2xN+4rO8Clc XnC39Oog==; Received: from [2600:1700:4830:165f::19e] (port=45330) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1k5GaQ-0002v9-CL; Mon, 10 Aug 2020 18:48:10 -0400 Subject: Re: [PATCH v4 1/5] counter: Internalize sysfs interface code To: William Breathitt Gray 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 References: <7209ac3d-d1ca-1b4c-b22c-8d98b13742e2@lechnology.com> <20200802210415.GA606173@shinobu> <4061c9e4-775e-b7a6-14fa-446de4fae537@lechnology.com> <20200809191500.GC6542@shinobu> From: David Lechner Message-ID: Date: Mon, 10 Aug 2020 17:48:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200809191500.GC6542@shinobu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >>>>> >>>>> CPMAC ETHERNET DRIVER >>>>> M: Florian Fainelli >>>>> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-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_channels[] = { >>>>> }; >>>>> >>>>> 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 patch. >>>> 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 type >>>> 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 the >>>> 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 there >>> 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 use 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 implementations >> could still use the proper enum type. > > Oh, I see what you mean now. So for example: > > int (*signal_read)(struct counter_device *counter, > struct counter_signal *signal, u8 *val) > > This will become instead: > > int (*signal_read)(struct counter_device *counter, > struct counter_signal *signal, u32 *val) > > Then in the driver callback implementation we use the enum type we need: > > enum counter_signal_level signal_level = COUNTER_SIGNAL_HIGH; > ... > *val = signal_level; > > Is that what you have in mind? > Yes. Additionally, if we have... int (*x_write)(struct counter_device *counter, ..., u32 val) We should be able to define the implementation as: static int my_driver_x_write(struct counter_device *counter, ..., enum some_type val) { ... } 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. int (*x_read)(struct counter_device *counter, ..., u32 *val) static int my_driver_x_read(struct counter_device *counter, ..., enum some_type *val) { ... }