public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Platform device matching
@ 2004-04-25 22:05 Kenn Humborg
  2004-04-25 23:00 ` Russell King
  0 siblings, 1 reply; 6+ messages in thread
From: Kenn Humborg @ 2004-04-25 22:05 UTC (permalink / raw)
  To: Linux-Kernel


I'm looking at the code for binding platform devices with drivers.  
However, platform_match() doesn't seem to agree with its kerneldoc
comment:

drivers/base/platform.c:
 50 /**
 51  *      platform_match - bind platform device to platform driver.
 52  *      @dev:   device.
 53  *      @drv:   driver.
 54  *
 55  *      Platform device IDs are assumed to be encoded like this: 
 56  *      "<name><instance>", where <name> is a short description of the 
 57  *      type of device, like "pci" or "floppy", and <instance> is the 
 58  *      enumerated instance of the device, like '' or '42'.
 59  *      Driver IDs are simply "<name>". 
 60  *      So, extract the <name> from the device, and compare it against 
 61  *      the name of the driver. Return whether they match or not.
 62  */
 63 
 64 static int platform_match(struct device * dev, struct device_driver * drv)
 65 {
 66         struct platform_device *pdev = container_of(dev, struct platform_device, dev);
 67 
 68         return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
 69 }

Shouldn't that really be

 64 static int platform_match(struct device * dev, struct device_driver * drv)
 65 {
 66         struct platform_device *pdev = container_of(dev, struct platform_device, dev);
 67 
 68         return (strncmp(pdev->name, drv->name, strlen(drv->name)) == 0);
 69 }

So that, for example, the 'floppy' driver will match with any of the 
'floppy', 'floppy0' and 'floppy1' devices?

Later,
Kenn



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Platform device matching
  2004-04-25 22:05 Platform device matching Kenn Humborg
@ 2004-04-25 23:00 ` Russell King
  2004-04-25 23:17   ` Kenn Humborg
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King @ 2004-04-25 23:00 UTC (permalink / raw)
  To: Kenn Humborg; +Cc: Linux-Kernel

On Sun, Apr 25, 2004 at 11:05:11PM +0100, Kenn Humborg wrote:
> I'm looking at the code for binding platform devices with drivers.  
> However, platform_match() doesn't seem to agree with its kerneldoc
> comment:

The code is correct as stands.  The documentation is behind times.  All
platform devices are "<name><instance-number>" so it's correct that the
"floppy" driver matches "floppy0" and "floppy1" etc.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Platform device matching
  2004-04-25 23:00 ` Russell King
@ 2004-04-25 23:17   ` Kenn Humborg
  2004-04-25 23:27     ` Russell King
  0 siblings, 1 reply; 6+ messages in thread
From: Kenn Humborg @ 2004-04-25 23:17 UTC (permalink / raw)
  To: Linux-Kernel

On Mon, Apr 26, 2004 at 12:00:50AM +0100, Russell King wrote:
> On Sun, Apr 25, 2004 at 11:05:11PM +0100, Kenn Humborg wrote:
> > I'm looking at the code for binding platform devices with drivers.  
> > However, platform_match() doesn't seem to agree with its kerneldoc
> > comment:
> 
> The code is correct as stands.  The documentation is behind times.  All
> platform devices are "<name><instance-number>" so it's correct that the
> "floppy" driver matches "floppy0" and "floppy1" etc.

Forgive me if I am being dense, but I still don't see how that works.  

The current code:

   return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);

will only return 1 if pdev->name and drv->name are _identical_ for the 
first 20 bytes.  Which "floppy" and "floppy0" are not.

Could it be that all current platform devices are initially named
as "<name>" and the instance number is only appended after matching
has been done?

Later,
Kenn



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Platform device matching
  2004-04-25 23:17   ` Kenn Humborg
@ 2004-04-25 23:27     ` Russell King
  2004-04-25 23:35       ` Kenn Humborg
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King @ 2004-04-25 23:27 UTC (permalink / raw)
  To: Kenn Humborg; +Cc: Linux-Kernel

On Mon, Apr 26, 2004 at 12:17:09AM +0100, Kenn Humborg wrote:
> On Mon, Apr 26, 2004 at 12:00:50AM +0100, Russell King wrote:
> > On Sun, Apr 25, 2004 at 11:05:11PM +0100, Kenn Humborg wrote:
> > > I'm looking at the code for binding platform devices with drivers.  
> > > However, platform_match() doesn't seem to agree with its kerneldoc
> > > comment:
> > 
> > The code is correct as stands.  The documentation is behind times.  All
> > platform devices are "<name><instance-number>" so it's correct that the
> > "floppy" driver matches "floppy0" and "floppy1" etc.
> 
> Forgive me if I am being dense, but I still don't see how that works.  

Sorry, I should've explained a little more.

pdev->name is the platform device name, which is just the <name> part.
pdev->dev.bus_id is the device model name, which is <name><instance-number>,
and the devices are known by this name.

Rather than going to the trouble of parsing <name> from the device model
name which would be inherently buggy, we reference it directly from the
platform_device structure.

So, this comment needs updating:

 *      So, extract the <name> from the device, and compare it against
 *      the name of the driver. Return whether they match or not.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Platform device matching
  2004-04-25 23:27     ` Russell King
@ 2004-04-25 23:35       ` Kenn Humborg
  2004-05-02  6:55         ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Kenn Humborg @ 2004-04-25 23:35 UTC (permalink / raw)
  To: Linux-Kernel

On Mon, Apr 26, 2004 at 12:27:33AM +0100, Russell King wrote:
> pdev->name is the platform device name, which is just the <name> part.
> pdev->dev.bus_id is the device model name, which is <name><instance-number>,
> and the devices are known by this name.
> 
> Rather than going to the trouble of parsing <name> from the device model
> name which would be inherently buggy, we reference it directly from the
> platform_device structure.

OK - I see it now.

> So, this comment needs updating:
> 
>  *      So, extract the <name> from the device, and compare it against
>  *      the name of the driver. Return whether they match or not.

Want a patch?

Later,
Kenn

--- drivers/base/platform.c~	2004-01-12 23:49:04.000000000 +0000
+++ drivers/base/platform.c	2004-04-26 00:33:43.000000000 +0100
@@ -57,8 +57,9 @@
  *	type of device, like "pci" or "floppy", and <instance> is the 
  *	enumerated instance of the device, like '0' or '42'.
  *	Driver IDs are simply "<name>". 
- *	So, extract the <name> from the device, and compare it against 
- *	the name of the driver. Return whether they match or not.
+ *	So, extract the <name> from the platform_device structure, 
+ *	and compare it against the name of the driver. Return whether 
+ *	they match or not.
  */
 
 static int platform_match(struct device * dev, struct device_driver * drv)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Platform device matching
  2004-04-25 23:35       ` Kenn Humborg
@ 2004-05-02  6:55         ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2004-05-02  6:55 UTC (permalink / raw)
  To: Kenn Humborg; +Cc: Linux-Kernel

On Mon, Apr 26, 2004 at 12:35:10AM +0100, Kenn Humborg wrote:
> On Mon, Apr 26, 2004 at 12:27:33AM +0100, Russell King wrote:
> > pdev->name is the platform device name, which is just the <name> part.
> > pdev->dev.bus_id is the device model name, which is <name><instance-number>,
> > and the devices are known by this name.
> > 
> > Rather than going to the trouble of parsing <name> from the device model
> > name which would be inherently buggy, we reference it directly from the
> > platform_device structure.
> 
> OK - I see it now.
> 
> > So, this comment needs updating:
> > 
> >  *      So, extract the <name> from the device, and compare it against
> >  *      the name of the driver. Return whether they match or not.
> 
> Want a patch?

Applied, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-05-02  6:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-25 22:05 Platform device matching Kenn Humborg
2004-04-25 23:00 ` Russell King
2004-04-25 23:17   ` Kenn Humborg
2004-04-25 23:27     ` Russell King
2004-04-25 23:35       ` Kenn Humborg
2004-05-02  6:55         ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox