[PATCH v6 09/23] clk: Add clock driver for the RISC-V RPMI clock service group
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Fri Jun 27 08:58:05 PDT 2025
On Fri, Jun 27, 2025 at 08:36:41PM +0530, Rahul Pathak wrote:
...
> > > > > + if (ret || rx.status)
> > > > > + return 0;
> > > >
> > > > Why rx.status can't be checked before calling to a sending message?
> > > > Sounds like the rpmi_mbox_init_send_with_response() links rx to msg somehow.
> > > > If this is the case, use msg here, otherwise move the check to be in the
> > > > correct place.
> > >
> > > Yes, the rpmi_mbox_init_send_with_response is a helper function which links
> > > the rx to msg. It's a very simple function which only performs assignments.
> > >
> > > Using msg instead of rx directly will require additional typecasting
> > > which will only clutter
> > > I can add a comment if that helps wherever the rpmi_mbox_init_send_with_response
> > > is used.
> >
> > This is besides harder-to-read code is kinda of layering violation.
> > If you afraid of a casting, add a helper to check for the status error.
> > Comment won't help much as making code better to begin with.
>
> Why using rx is the issue in the first place when it's the same layer
> which links the rx with msg using the helper function and then
> uses it directly? Infact using rx directly avoids unnecessary code
> which is only increasing redundant code which ultimately results in
> same thing. Even if I add a helper function that will require additional
> pointer passing with NULL checking which all is currently avoided.
> And, we are not just talking about rx.status but a lot of other fields.
Because it's simply bad code, look at the simplified model:
int foo, bar;
int ret;
func_1(..., &foo, &bar);
ret = func_2(&foo);
if (ret || bar)
...do something...
When one reads this code the immediate reaction will be like mine.
This is also (without deeper understanding) tempting to someone
who even thinks that the code can be simplified (w/o knowing that it
may not) to change it as
func_1(..., &foo, &bar);
if (bar)
...do something...
ret = func_2(&foo);
if (ret)
...do something...
Using msg is the right thing to do. In that way there is no questions asked
and everything is clear. Also why layering violation? Because the conditional
requires to know the guts of rx in the code which doesn't use rx that way
(or rather using it as semi-opaque object).
--
With Best Regards,
Andy Shevchenko
More information about the linux-riscv
mailing list