Re: Platform device matching, & weird strncmp usage

From: Benjamin Herrenschmidt
Date: Fri Jan 06 2006 - 16:38:19 EST


On Fri, 2006-01-06 at 18:53 +0000, Russell King wrote:
> On Fri, Jan 06, 2006 at 04:59:39PM +1100, Benjamin Herrenschmidt wrote:
> > static int platform_match(struct device * dev, struct device_driver * drv)
> > {
> > struct platform_device *pdev = container_of(dev, struct platform_device, dev);
> >
> > return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
> > }
> >
> > As far as I know, strncmp() is _NOT_ supposed to return 0 if one string
> > is shorter than the other and they match until that point. Thus the
> > above will never match unless the <name> portion of pdev->name is
> > exactly of size BUS_ID_SIZE which is obviously not the case...
>
> pdev->name is just the <name> part - it's pdev->dev.name which has
> both the <name> and <instance>. I think the strncmp is unnecessary,
> and it can be replaced by a plain strcmp.

Ah indeed, I got confused by having both strings.

Ben.


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