Re: [PATCH v8 5/9] block: implement NVMEM provider
Loic Poulain <[email protected]> Fri, 24 Jul 2026 11:10:58 +0200
| Newsgroups | org.infradead.lists.ath10k,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-block,org.kernel.vger.linux-bluetooth,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-mmc,org.kernel.vger.linux-wireless,org.kernel.vger.netdev |
|---|---|
| Message-ID | <CAFEp6-1_iariDyqWj0KezHAtULSO+piPHX0F=Z46Rx4KDNLmXw@mail.gmail.com> |
Hi Christoph, On Fri, Jul 24, 2026 at 6:57=E2=80=AFAM Christoph Hellwig <[email protected]= g> wrote: > > On Fri, Jul 03, 2026 at 03:45:18PM +0200, Loic Poulain wrote: > > + Allow block devices (or partitions) to act as NVMEM providers, > > Based on the code below I don't think you actually support partitions. Right, I was planning to add partition support in a follow-up series. But since this is really supposed to be a block-agnostic feature, whether it's a disk or a partition, I'll include partition in v8. > > > +static int blk_nvmem_reg_read(void *priv, unsigned int from, void *val= , size_t bytes) > > Overly long line. > > > +{ > > + dev_t devt =3D (dev_t)(uintptr_t)priv; > > + size_t bytes_left =3D bytes; > > + loff_t pos =3D from; > > + int ret =3D 0; > > + > > + struct file *bdev_file __free(fput) =3D > > + bdev_file_open_by_dev(devt, BLK_OPEN_READ, NULL, NULL); > > Please try to avoid all that magic autfree stuff that makes the code > impossible to read about. Ack, I've received mixed feedback on this. However, given that there aren't any particularly complex or numerous exit paths, I guess the explicit release will make the code clearer. > > + if (IS_ERR(bdev_file)) > > + return PTR_ERR(bdev_file); > > + > > + while (bytes_left) { > > .. and just use __kernel_read instead of badly reimplementing it. Ack. > > > + config.name =3D dev_name(dev); > > + config.owner =3D THIS_MODULE; > > + config.priv =3D (void *)(uintptr_t)dev->devt; > > Why is this storing the dev_t and not the block device itself? It was originally intended to avoid races with device removal, but now that we're synchronized with the block subsystem, that's no longer strictly necessary. > > > + > > + blk_nvmem_add(disk->part0); > > Hmm, and you're always doing it for the whole device. So the intefaces > really should be based on a gendisk, not a block_device. I will add it for partitions as well. > > Also once you register the whole devices as nvmem provider, we really > should keep it from being used a block device, shouldn't we? I'm not sure, the whole concept is block backed NVMEM, so we still need to add that block as base layer, though we could discuss suppressing uevent for it. Preventing block usage would make the feature much more intrusive than other NVMEM providers like MTD, where the underlying device stays accessible. And we may genuinely still want to write the disk (e.g. for factory provisioning), updating the very data the cells point to, etc. There's also the layering aspect, if a disk (e.g. mmcblk0) has logical partitions on top (mmcblk0pX), we still register/expose the whole disk mmcblk0 as a block device regardless. So if a disk contains NVMEM cells, I think it should still be exposed as a block device as well. Regards, Loic