Re: [PATCH v7 7/9] PCI/IDE: Add IDE establishment helpers

dan.j.williams
2025-10-29T18:57:29Z

Aneesh Kumar K.V wrote:
> Dan Williams <dan.j.williams@intel.com> writes:
> ...
>
> > +DEFINE_FREE(free_stream, struct stream_index *, if (_T) free_stream_index(_T))
> > +static struct stream_index *alloc_stream_index(struct ida *ida, u8 max,
> > + struct stream_index *stream)
> > +{
> > + int id;
> > +
> > + if (!max)
> > + return NULL;
> > +
> > + id = ida_alloc_range(ida, 0, max - 1, GFP_KERNEL);
> > + if (id < 0)
> > + return NULL;
> > +
> > + *stream = (struct stream_index) {
> > + .ida = ida,
> > + .stream_index = id,
> > + };
> > + return stream;
> > +}
> > +
>
> We do
>
> struct stream_index *hb_stream __free(free_stream) = alloc_stream_index(
> &hb->ide_stream_ida, hb->nr_ide_streams, &__stream[PCI_IDE_HB]);
>
> and the default value for hb->nr_ide_streams is 256
>
> void pci_ide_init_host_bridge(struct pci_host_bridge *hb)
> {
> hb->nr_ide_streams = 256;
> }
>
> That overflows the u8 max argument for alloc_stream_index and results in
> a NULL return.

Ah, I missed this straggling u8. I missed this failure because the
samples/devsec/ implementation sets the host bridge pool to something
less than 256. Will fix.