Re: [PATCH 04/13] PCI: acpiphp: remove 'name' parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Rolf Eike Beer <eike-kernel@xxxxxxxxx>:
> Alex Chiang wrote:
> > * Rolf Eike Beer <eike-kernel@xxxxxxxxx>:
> > > Alex Chiang wrote:
> > > >
> > > > +static inline const char *slot_name(struct slot *slot)
> > > > +{
> > > > +	return hotplug_slot_name(slot->hotplug_slot);
> > > > +}
> > > > +
> > > >  /*
> > > >   * struct acpiphp_bridge - PCI bridge information
> > > >   *
> > >
> > > I don't see a point in this function. Why not call hotplug_slot_name()
> > > directly?
> >
> > You're correct that we don't exactly need it in acpiphp. However,
> > it is a useful helper function for some of the other drivers, and
> > I thought it would be better to keep consistency if possible.
> 
> I looked into all other patches and the function is the same in every one.

For example, in shpchp, I use slot_name() in both shpchp_core.c
and in shpchp_ctrl.c. This is the case for a few other drivers
too.

Based on that reasoning, I felt a little consistency across
drivers was warranted. Besides, the generated code should be the
same.

> > > >  	acpiphp_slot->slot = slot;
> > > > -	snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun);
> > > > +	memset(name, 0, SLOT_NAME_SIZE);
> > > > +	snprintf(name, SLOT_NAME_SIZE, "%u", slot->acpi_slot->sun);
> > >
> > > The memset() is not needed at all. And the sizeof is IMHO a good idea
> > > anyway as it allows to get rid of the define.
> >
> > Hm, don't need a memset? I won't have garbage on the stack?
> > </n00b>
> 
> Yes, you have garbage on the stack. But snprintf() does not care what is in 
> the buffer before it starts and the result is 0-terminated afterwards.

Ok, you're right. For some reason, I was thinking that there were
versions of snprintf() that did not NULL-terminate in the event
of truncation, but I checked the kernel implementation, and it
does NULL terminate in either case.

Besides, it looks like I should be using scnprintf() instead. So
I'll rework the patches.
 
> > On the other hand, keeping the #define is important, because
> > again, that's the established convention of the PCI hotplug
> > drivers.
> 
> I would not bet on this. It has been there and copied around
> from one driver to the other. If we can get rid of those I
> guess noone would be upset. And you introduced at least two of
> them ;) Jesse? 

The #define exists in the original pcihp_skeleton.c example.

This is perhaps the 2nd or 3rd time I've swept through the
PCI hotplug drivers for cleanups, and for me, I really prefer
some sort of consistency, otherwise I go insane trying to keep
track of the differences.

But I will defer to Jesse's opinion.

Thanks,

/ac

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux