[RFC PATCH] nvme-core: add helper to get nvme_ctrl from device

Sagi Grimberg sagi at grimberg.me
Wed May 17 03:45:36 PDT 2023


> Hi Sagi,
> 
> On 5/17/23 00:12, Sagi Grimberg wrote:
>>
>>> Just like we have other helpers to_nvmet_port(), to_nvmet_ns(),
>>> ana_groups_to_port() and to_nvmet_ns(), add a helper to get nvme_ctr
>>> from struct device.
>>
>> I don't think this is very useful.
> 
> it's the same pattern we have used everywhere in the nvme code,
> I did not invent anything new here ...

Still I don't find it very useful. get drvdata from a device is probably
the most common helper in device-driver territory, not sure why we want
to add a helper on top of it.

>>> Note that this removes the bunch of nvme_ctrl declaration code that is
>>> needed to get the nvme_ctrl from struct device in the host/core.c.
>>> Followwing is the diff :-
>>
>> It doesn't make it easier on my eyes...
>>
> 
> I failed to understand how this is different from examples mentioned above
> which are part of existing code reducing ~20 lines in current code and
> future code for a variable declaration that is only accessed once ?

It adds an accessor on top of an accessor. The reduction of declaration
code does not by definition make the code simpler. and personally I
don't think that making bar->x->y foo_to_bar(foo)->x->y is necessarily
an improvement.

If others think its worth while to change, I won't object, I just said
that I don't think its very useful.



More information about the Linux-nvme mailing list