Re: [PATCH v10 1/3] nvmem: core: Rework layouts to become platform devices

From: Miquel Raynal
Date: Thu Oct 05 2023 - 11:43:17 EST


Hi Miquel,

miquel.raynal@xxxxxxxxxxx wrote on Tue, 3 Oct 2023 11:43:26 +0200:

> Hi Srinivas,
>
> > > +static int nvmem_dev_match_available_layout(struct device *dev, void *data)
> > > +{
> > > + struct nvmem_device *nvmem = to_nvmem_device(dev);
> > > +
> > > + return nvmem_match_available_layout(nvmem);
> > > +}
> > > +
> > > +static int nvmem_for_each_dev(int (*fn)(struct device *dev, void *data))
> > > +{
> > > + return bus_for_each_dev(&nvmem_bus_type, NULL, NULL, fn);
> > > +}
> > > +
> > > +/*
> > > + * When an NVMEM device is registered, try to match against a layout and
> > > + * populate the cells. When an NVMEM layout is probed, ensure all NVMEM devices
> > > + * which could use it properly expose their cells.
> > > + */
> > > +static int nvmem_notifier_call(struct notifier_block *notifier,
> > > + unsigned long event_flags, void *context)
> > > +{
> > > + struct nvmem_device *nvmem = NULL;
> > > + int ret;
> > > +
> > > + switch (event_flags) {
> > > + case NVMEM_ADD:
> > > + nvmem = context;
> > > + break;
> > > + case NVMEM_LAYOUT_ADD:
> > > + break;
> > > + default:
> > > + return NOTIFY_DONE;
> > > + }
> >
> > It looks bit unnatural for core to register notifier for its own events.
> >
> >
> > Why do we need the notifier at core level, can we not just handle this in core before raising these events, instead of registering a notifier cb?
>
> There is no good place to do that "synchronously". We need some kind of
> notification mechanism in these two cases:
> * A memory device is being probed -> if a matching layout driver is
> already available, we need to parse the device and expose the cells,
> but not in the thread registering the memory device.
> * A layout driver is being insmod'ed -> if a memory device needs it to
> create cells we need to parse the device content, but I find it
> crappy to start device-specific parsing in the registration handler.
>
> So probe of the memory device is not a good place for this, nor is the
> registration of the layout driver. Yet, we need to do the same
> operation upon two different "events".
>
> This notifier mechanism is a clean and easy way to get notified and
> implement a callback which is also not blocking the thread doing the
> initial registration. I am personally not bothered using it only
> internally. If you have another mechanism in mind to perform a similar
> operation, or a way to avoid this need I'll do the switch.

Since I've changed the way nvmem devices and layouts are dependent in
v11, I've been giving this a second thought and I think this can now be
avoided. I've improved the layout registration callback to actually
retrieve the nvmem device this layout is probing on and populates
the dynamic cells *there* (instead of during the probe of the nvmem
device itself). This way I could drop some boilerplate which is no
longer necessary. It comes at a low cost: there are now two places were
sysfs cells can be added.

I am cleaning up all this stuff and then let you and Greg review the
v12.

Thanks,
Miquèl