Re: [PATCH v6 1/5] firmware: qcom_scm: provide a read-modify-write function

From: andy . shevchenko
Date: Fri May 26 2023 - 18:22:40 EST


Wed, Mar 29, 2023 at 01:16:48PM +0530, Mukesh Ojha kirjoitti:
> It was realized by Srinivas K. that there is a need of
> read-modify-write scm exported function so that it can
> be used by multiple clients.
>
> Let's introduce qcom_scm_io_update_field() which masks
> out the bits and write the passed value to that
> bit-offset. Subsequent patch will use this function.

...

> + new = (old & ~mask) | val << (ffs(mask) - 1);

It's a bit non-standard to see left shift here instead of masking.

new = (old & ~mask) | (val & mask);

is usual pattern.

Note as well that your code is prone to subtle mistakes when overflow may
easily override bits outside the mask.

> + return qcom_scm_io_writel(addr, new);
> +}

--
With Best Regards,
Andy Shevchenko