[PATCH v11 2/8] power: reset: reboot-mode: Add support for 64 bit magic

Andrew Lunn andrew at lunn.ch
Sat Jul 19 09:57:36 PDT 2025


> >> +static int qcom_pon_reboot_mode_write(struct reboot_mode_driver *reboot, u64 magic)
> >>  {
> >>  	struct qcom_pon *pon = container_of
> >>  			(reboot, struct qcom_pon, reboot_mode);
> >> @@ -37,7 +36,7 @@ static int qcom_pon_reboot_mode_write(struct reboot_mode_driver *reboot,
> >>  	ret = regmap_update_bits(pon->regmap,
> >>  				 pon->baseaddr + PON_SOFT_RB_SPARE,
> >>  				 GENMASK(7, pon->reason_shift),
> >> -				 magic << pon->reason_shift);
> >> +				 ((u32)magic) << pon->reason_shift);

As a general rule of thumb, code with casts is poor quality code. Try
to write the code without casts.

Maybe something like

      If (magic > MAX_U32)
      	   return -EINVAL;

      magic_32 = magic;

You might be able to go further, and validate that magic actually fits
into the field when you consider the << pon->reason_shift.

	Andrew



More information about the linux-arm-kernel mailing list