On Tue, 2023-02-07 at 21:55 -0800, Dan Williams wrote:
> Vishal Verma wrote:
> >
<..>
> > +static void set_type_from_decoder(struct cxl_ctx *ctx, struct
> > parsed_params *p)
> > +{
> > + int num_cap = 0;
> > +
> > + /* if param.type was explicitly specified, nothing to do here */
> > + if (param.type)
> > + return;
> > +
> > + /*
> > + * if the root decoder only has one type of capability, default
> > + * to that mode for the region.
> > + */
> > + if (cxl_decoder_is_pmem_capable(p->root_decoder))
> > + num_cap++;
> > + if (cxl_decoder_is_volatile_capable(p->root_decoder))
> > + num_cap++;
> > +
> > + if (num_cap == 1) {
> > + if (cxl_decoder_is_volatile_capable(p->root_decoder))
> > + p->mode = CXL_DECODER_MODE_RAM;
> > + else if (cxl_decoder_is_pmem_capable(p->root_decoder))
> > + p->mode = CXL_DECODER_MODE_PMEM;
> > + }
>
> Is @num_cap needed? I.e. if this just does:
>
> if (cxl_decoder_is_volatile_capable(p->root_decoder))
> p->mode = CXL_DECODER_MODE_RAM;
> if (cxl_decoder_is_pmem_capable(p->root_decoder))
> p->mode = CXL_DECODER_MODE_PMEM;
>
> ...then it matches the changelog of defaulting to pmem if both types are
> set, and otherwise the single capability dominates.
Oh true, that's clever! I hope it isn't too clever for future-me when
coming across this and wondering what is happening, but for now I like
it, so I'll run with it :)