Re: (EXT) Re: (EXT) Re: [PATCH mmc-next v2] mmc: allow setting slot index via device tree alias

From: Matthias Schiffer
Date: Tue Aug 25 2020 - 08:32:47 EST


On Tue, 2020-08-25 at 14:27 +0200, Ulf Hansson wrote:
> On Tue, 25 Aug 2020 at 14:00, Matthias Schiffer
> <matthias.schiffer@xxxxxxxxxxxxxxx> wrote:
> >
> > On Tue, 2020-08-25 at 11:39 +0200, Matthias Schiffer wrote:
> > > On Tue, 2020-08-25 at 11:14 +0200, Ulf Hansson wrote:
> > > > On Thu, 20 Aug 2020 at 09:59, Matthias Schiffer
> > > > <matthias.schiffer@xxxxxxxxxxxxxxx> wrote:
> > > > > --- a/drivers/mmc/core/host.c
> > > > > +++ b/drivers/mmc/core/host.c
> > > > > @@ -387,6 +387,7 @@ struct mmc_host *mmc_alloc_host(int
> > > > > extra,
> > > > > struct device *dev)
> > > > > {
> > > > > int err;
> > > > > struct mmc_host *host;
> > > > > + int alias_id, min_idx, max_idx;
> > > > >
> > > > > host = kzalloc(sizeof(struct mmc_host) + extra,
> > > > > GFP_KERNEL);
> > > > > if (!host)
> > > > > @@ -395,7 +396,18 @@ struct mmc_host *mmc_alloc_host(int
> > > > > extra,
> > > > > struct device *dev)
> > > > > /* scanning will be enabled when we're ready */
> > > > > host->rescan_disable = 1;
> > > > >
> > > > > - err = ida_simple_get(&mmc_host_ida, 0, 0,
> > > > > GFP_KERNEL);
> > > > > + host->parent = dev;
> > > > > +
> > > > > + alias_id = mmc_get_reserved_index(host);
> > > > > + if (alias_id >= 0) {
> > > > > + min_idx = alias_id;
> > > > > + max_idx = alias_id + 1;
> > > > > + } else {
> > > > > + min_idx = mmc_first_nonreserved_index();
> > > > > + max_idx = 0;
> > > > > + }
> > > > > +
> > > > > + err = ida_simple_get(&mmc_host_ida, min_idx, max_idx,
> > > > > GFP_KERNEL);
> >
> >
> > One more question I came across when reworking my patch: Do we need
> > a
> > fallback here for the case where the reserved index is already
> > taken?
> > To handle an SD card being replaced while still mounted?
>
> Removal/insertion of an SD card should be fine, as that doesn't mean
> that the host is removed. In other words, host->index remains the
> same.
>
> Although, for a bad DT configuration, where for example the same
> aliases id is used twice, a fallback could make sense. On the other
> hand, as such configuration would be wrong, we might as well just
> print a message and return an error.

I don't think this can happen as long as we don't have DTs changing at
runtime: Each alias is a DT property name in /aliases, which can only exist once.


>
> [...]
>
> Kind regards
> Uffe