Am Mittwoch, 14. November 2007 schrieb Alex Chiang:
quoted text > Hi Eike,
>
> * Rolf Eike Beer <eike-hotplug@sf-tec.de>:
> > Alex Chiang wrote:
> > > --- a/drivers/pci/hotplug/fakephp.c
> > > +++ b/drivers/pci/hotplug/fakephp.c
> > > @@ -93,6 +93,7 @@ static int add_slot(struct pci_dev *dev)
> > > struct dummy_slot *dslot;
> > > struct hotplug_slot *slot;
> > > int retval =3D -ENOMEM;
> > > + static int count =3D 1;
> > >
> > > slot =3D kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
> > > if (!slot)
> > > @@ -106,7 +107,8 @@ static int add_slot(struct pci_dev *dev)
> > > slot->info->max_bus_speed =3D PCI_SPEED_UNKNOWN;
> > > slot->info->cur_bus_speed =3D PCI_SPEED_UNKNOWN;
> > >
> > > - slot->name =3D &dev->dev.bus_id[0];
> > > + slot->name =3D kmalloc(8, GFP_KERNEL);
> > > + sprintf(slot->name, "fake%d", count++);
> > > dbg("slot->name =3D %s\n", slot->name);
> > >
> > > dslot =3D kmalloc(sizeof(struct dummy_slot), GFP_KERNEL);
> >
> > This is ugly. Please do it the way we already do e.g. for
> > acpiphp: add a char[8] to "struct dummy_slot" and just
> > reference that here.
>
> I took at look at the code in acpiphp you're talking about, and
> I'm not sure why you think the above is "ugly". We're talking
> about a runtime vs compile time storage for the name, and doing a
> kmalloc/sprintf is a pretty standard idiom.
>
> BTW, I did incorporate both Linas' and Willy's comments, by
> changing the kmalloc size to an explicit 32, and using snprintf
> instead.
>
> In any case, for your particular comment, I think I'm going to
> leave it alone for now, and let Greg weigh in with the final
> recommendation.
Because we have another allocation of very small size for every slot here.
struct dummy_slot has a size of 4 pointers, that's 16 byte for 32 bit=20
architectures. Putting 8 byte of additional storage here would save a=20
complete allocation on 32 bit platforms. For 64 bit platforms the memory=20
usage is the same but we do less allocations (i.e. less points to fail) and=
=20
less memory fragmentation.
Btw: your code lacks a check if kmalloc() returns NULL.
Eike