lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c9693c60-3dad-4970-ad99-264592f427d8@wanadoo.fr>
Date: Sat, 5 Jul 2025 00:37:57 +0900
From: Vincent Mailhol <mailhol.vincent@...adoo.fr>
To: Biju Das <biju.das.jz@...renesas.com>
Cc: Fabrizio Castro <fabrizio.castro.jz@...esas.com>,
 "linux-can@...r.kernel.org" <linux-can@...r.kernel.org>,
 "linux-renesas-soc@...r.kernel.org" <linux-renesas-soc@...r.kernel.org>,
 "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
 Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@...renesas.com>,
 "biju.das.au" <biju.das.au@...il.com>, Marc Kleine-Budde
 <mkl@...gutronix.de>, Geert Uytterhoeven <geert+renesas@...der.be>,
 Magnus Damm <magnus.damm@...il.com>
Subject: Re: [PATCH 4/4] can: rcar_canfd: Replace RCANFD_CFG_* macros with
 FIELD_PREP

On 04/07/2025 at 19:12, Biju Das wrote:
> Hi Vincent,
> 
> Thanks for the feedback.
> 
>> -----Original Message-----
>> From: Vincent Mailhol <mailhol.vincent@...adoo.fr>
>> Sent: 04 July 2025 03:25
>> Subject: Re: [PATCH 4/4] can: rcar_canfd: Replace RCANFD_CFG_* macros with FIELD_PREP
>>
>> Hi Biju,
>>
>> On 04/07/2025 at 03:34, Biju Das wrote:
>>> Replace RCANFD_CFG_* macros with simpler FIELD_PREP macro.
>>>
>>> Signed-off-by: Biju Das <biju.das.jz@...renesas.com>
>>> ---
>>>  drivers/net/can/rcar/rcar_canfd.c | 10 ++--------
>>>  1 file changed, 2 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
>>> index b5b059e83374..dd87b4e8e688 100644
>>> --- a/drivers/net/can/rcar/rcar_canfd.c
>>> +++ b/drivers/net/can/rcar/rcar_canfd.c
>>> @@ -102,12 +102,6 @@
>>>
>>>  /* Channel register bits */
>>>
>>> -/* RSCFDnCmCFG - Classical CAN only */
>>> -#define RCANFD_CFG_SJW(x)		(((x) & 0x3) << 24)
>>> -#define RCANFD_CFG_TSEG2(x)		(((x) & 0x7) << 20)
>>> -#define RCANFD_CFG_TSEG1(x)		(((x) & 0xf) << 16)
>>> -#define RCANFD_CFG_BRP(x)		(((x) & 0x3ff) << 0)
>>> -
>>>  /* RSCFDnCFDCmCTR / RSCFDnCmCTR */
>>>  #define RCANFD_CCTR_CTME		BIT(24)
>>>  #define RCANFD_CCTR_ERRD		BIT(23)
>>> @@ -1418,8 +1412,8 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev)
>>>  	if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || gpriv->info->shared_can_regs) {
>>>  		cfg = rcar_canfd_compute_nominal_bit_rate_cfg(gpriv->info, tseg1, brp, sjw, tseg2);
>>>  	} else {
>>> -		cfg = (RCANFD_CFG_TSEG1(tseg1) | RCANFD_CFG_BRP(brp) |
>>> -		       RCANFD_CFG_SJW(sjw) | RCANFD_CFG_TSEG2(tseg2));
>>> +		cfg = FIELD_PREP(GENMASK(19, 16), tseg1) | FIELD_PREP(GENMASK(9, 0), brp) |
>>> +		      FIELD_PREP(GENMASK(25, 24), sjw) | FIELD_PREP(GENMASK(22, 20), tseg2);
>>>  	}
>>
>> You can still keep the macro definition to give a meaning to the magic number:
>>
>>   #define RCANFD_CFG_SJW_MASK GENMASK(25, 24)
>>
>> and do a:
>>
>>   FIELD_PREP(RCANFD_CFG_SJW_MASK, sjw)
> 
> Are you ok for the below change to reduce the changes minimum??
> 
> -#define RCANFD_CFG_SJW(x)		(((x) & 0x3) << 24)
> +#define RCANFD_CFG_SJW(x)		FIELD_PREP(GENMASK(25, 24), x))

No more function-like macro please :)

Normal macro definitions are totally welcome. These allow to attach a name to
otherwise totally meaningless magic numbers.

When it goes to the actual calculation, functions are best.

> Or
> 
> you want RCANFD_CFG_SJW_MASK as separate one as you suggested?

This please :)


Yours sincerely,
Vincent Mailhol


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ