linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Missing usb_find_device symbol from usb.c
@ 2008-01-22 19:18 Wilco Beekhuizen
  2008-01-22 22:08 ` Adrian Bunk
  2008-01-24  1:37 ` Greg KH
  0 siblings, 2 replies; 23+ messages in thread
From: Wilco Beekhuizen @ 2008-01-22 19:18 UTC (permalink / raw)
  To: linux-kernel

2.6.24-rc8 (possibly lower rc's too) has usb_find_device removed from
usb.c. This causes problems when compiling modules that need
usb_find_device.
This patch puts the symbol back in place. Unless someone has a good
reason not to include usb_find_device?

--- linux-2.6.24-rc8/drivers/usb/core/usb.c.bak 2008-01-22
20:12:37.000000000 +0100
+++ linux-2.6.24-rc8/drivers/usb/core/usb.c     2008-01-22
20:12:52.000000000 +0100
@@ -1007,6 +1007,7 @@

 EXPORT_SYMBOL(__usb_get_extra_descriptor);

+EXPORT_SYMBOL(usb_find_device);
 EXPORT_SYMBOL(usb_get_current_frame_number);

 EXPORT_SYMBOL(usb_buffer_alloc);

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-22 19:18 [PATCH] Missing usb_find_device symbol from usb.c Wilco Beekhuizen
@ 2008-01-22 22:08 ` Adrian Bunk
  2008-01-24  1:37 ` Greg KH
  1 sibling, 0 replies; 23+ messages in thread
From: Adrian Bunk @ 2008-01-22 22:08 UTC (permalink / raw)
  To: Wilco Beekhuizen; +Cc: linux-kernel

On Tue, Jan 22, 2008 at 08:18:32PM +0100, Wilco Beekhuizen wrote:

> 2.6.24-rc8 (possibly lower rc's too) has usb_find_device removed from
> usb.c. This causes problems when compiling modules that need
> usb_find_device.
> This patch puts the symbol back in place. Unless someone has a good
> reason not to include usb_find_device?
>...

The good reason is that there is no longer any in-kernel user of this 
export, and the kernel does not offer APIs only for external modules.

If there's no in-kernel users that's also a light indication that it 
might not be the correct API to use.

Tell the vendors of the modules using it that they should submit their 
modules for inclusion in the kernel.

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-22 19:18 [PATCH] Missing usb_find_device symbol from usb.c Wilco Beekhuizen
  2008-01-22 22:08 ` Adrian Bunk
@ 2008-01-24  1:37 ` Greg KH
  2008-01-24 10:05   ` Wilco Beekhuizen
  1 sibling, 1 reply; 23+ messages in thread
From: Greg KH @ 2008-01-24  1:37 UTC (permalink / raw)
  To: Wilco Beekhuizen; +Cc: linux-kernel

On Tue, Jan 22, 2008 at 08:18:32PM +0100, Wilco Beekhuizen wrote:
> 2.6.24-rc8 (possibly lower rc's too) has usb_find_device removed from
> usb.c. This causes problems when compiling modules that need
> usb_find_device.
> This patch puts the symbol back in place. Unless someone has a good
> reason not to include usb_find_device?

I don't see any users in the kernel tree of this function that can be
built as a module.

Do you know of any external modules that need it?  Any pointers to the
code anywhere?

thanks,

greg k-h

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24  1:37 ` Greg KH
@ 2008-01-24 10:05   ` Wilco Beekhuizen
  2008-01-24 11:19     ` Pekka Enberg
  0 siblings, 1 reply; 23+ messages in thread
From: Wilco Beekhuizen @ 2008-01-24 10:05 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

2008/1/24, Greg KH <greg@kroah.com>:
> On Tue, Jan 22, 2008 at 08:18:32PM +0100, Wilco Beekhuizen wrote:
> > 2.6.24-rc8 (possibly lower rc's too) has usb_find_device removed from
> > usb.c. This causes problems when compiling modules that need
> > usb_find_device.
> > This patch puts the symbol back in place. Unless someone has a good
> > reason not to include usb_find_device?
>
> I don't see any users in the kernel tree of this function that can be
> built as a module.
>
> Do you know of any external modules that need it?  Any pointers to the
> code anywhere?
>
> thanks,
>
> greg k-h
>

Well I need it for my iriver mp3 player. This driver currently resides
here: http://www.init0.nl/iriver.php

Most code is pretty ancient, I just manage it so it compiles with
recent kernels. Is there somehting exported that is similar to
usb_find_device?

Wilco

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 10:05   ` Wilco Beekhuizen
@ 2008-01-24 11:19     ` Pekka Enberg
  2008-01-24 11:49       ` Oliver Neukum
  2008-01-24 16:44       ` Greg KH
  0 siblings, 2 replies; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 11:19 UTC (permalink / raw)
  To: Wilco Beekhuizen; +Cc: Greg KH, linux-kernel

Hi Wilco,

On Jan 24, 2008 12:05 PM, Wilco Beekhuizen <wilcobeekhuizen@gmail.com> wrote:
> Most code is pretty ancient, I just manage it so it compiles with
> recent kernels. Is there somehting exported that is similar to
> usb_find_device?

The problem is that iriverfs shouldn't be calling usb_find_device() at
all. What happens when you plug in two players to the same computer?
AFAICT the whole thing should be a proper USB driver in drivers/usb/
and not a "filesystem" in fs/.

                          Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 11:19     ` Pekka Enberg
@ 2008-01-24 11:49       ` Oliver Neukum
  2008-01-24 11:52         ` Pekka Enberg
  2008-01-24 16:44       ` Greg KH
  1 sibling, 1 reply; 23+ messages in thread
From: Oliver Neukum @ 2008-01-24 11:49 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Am Donnerstag, 24. Januar 2008 12:19:25 schrieb Pekka Enberg:
> AFAICT the whole thing should be a proper USB driver in drivers/usb/
> and not a "filesystem" in fs/

A quick glance through the files at sourceforge indicates that this
device use a file transfer protocol. Mapping this to a simple device
is hard. A fs is quite natural a representation of that.

	Regards
		Oliver

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 11:49       ` Oliver Neukum
@ 2008-01-24 11:52         ` Pekka Enberg
  2008-01-24 12:24           ` Oliver Neukum
  0 siblings, 1 reply; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 11:52 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Hi Oliver,

On Jan 24, 2008 1:49 PM, Oliver Neukum <oliver@neukum.org> wrote:
> A quick glance through the files at sourceforge indicates that this
> device use a file transfer protocol. Mapping this to a simple device
> is hard. A fs is quite natural a representation of that.

Sure but the filesystems in fs/ are general purpose and they can be
mounted on top of any block device (except for the in-memory ones like
sysfs). Furthermore, the problem with iriverfs is that it assumes that
there can be only one device plugged to the host. What we want is
something like

  $ mount -t iriverfs /dev/iriver0 /mnt/media

Which can be accomplished with an USB driver in driver/usb/ that
registers the special iriverfs.

                        Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 11:52         ` Pekka Enberg
@ 2008-01-24 12:24           ` Oliver Neukum
  2008-01-24 12:34             ` Pekka Enberg
  0 siblings, 1 reply; 23+ messages in thread
From: Oliver Neukum @ 2008-01-24 12:24 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Am Donnerstag, 24. Januar 2008 12:52:45 schrieb Pekka Enberg:
> Hi Oliver,
> 
> On Jan 24, 2008 1:49 PM, Oliver Neukum <oliver@neukum.org> wrote:
> > A quick glance through the files at sourceforge indicates that this
> > device use a file transfer protocol. Mapping this to a simple device
> > is hard. A fs is quite natural a representation of that.
> 
> Sure but the filesystems in fs/ are general purpose and they can be
> mounted on top of any block device (except for the in-memory ones like

nfs, cifs, jffs, ...

> sysfs). Furthermore, the problem with iriverfs is that it assumes that
> there can be only one device plugged to the host. What we want is
> something like
> 
>   $ mount -t iriverfs /dev/iriver0 /mnt/media
> 
> Which can be accomplished with an USB driver in driver/usb/ that
> registers the special iriverfs.

And what happens if you do
mount -t vfat /dev/iriver0 /mnt/media ?

	Regards
		Oliver

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 12:24           ` Oliver Neukum
@ 2008-01-24 12:34             ` Pekka Enberg
  2008-01-24 12:58               ` Oliver Neukum
  0 siblings, 1 reply; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 12:34 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Hi Oliver,

On Jan 24, 2008 2:24 PM, Oliver Neukum <oliver@neukum.org> wrote:
> > Sure but the filesystems in fs/ are general purpose and they can be
> > mounted on top of any block device (except for the in-memory ones like
>
> nfs, cifs, jffs, ...

But none of them mess around with *hardware*. Sure, you can split it
in two: driver and filesystem but yet again, the latter is not general
purpose at all. I think this is somewhat similar to spufs which is
really hardware specific and thus not eligible for fs/.

On Jan 24, 2008 2:24 PM, Oliver Neukum <oliver@neukum.org> wrote:
> > sysfs). Furthermore, the problem with iriverfs is that it assumes that
> > there can be only one device plugged to the host. What we want is
> > something like
> >
> >   $ mount -t iriverfs /dev/iriver0 /mnt/media
> >
> > Which can be accomplished with an USB driver in driver/usb/ that
> > registers the special iriverfs.
>
> And what happens if you do
> mount -t vfat /dev/iriver0 /mnt/media ?

If /dev/iriver0 is registered as a block device, we read the
superblock but don't find a vfat filesystem and the mount fails as
expected. As for

   mount -t iriverfs /dev/sd1 /mnt/media

we need to make sure file_system_type->get_sb() does something like
what drivers/mtd/mtdsuper.c::get_sb_mtd() does to make sure we only
let it mount if the block device is indeed an iriver player.

                        Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 12:34             ` Pekka Enberg
@ 2008-01-24 12:58               ` Oliver Neukum
  2008-01-24 13:14                 ` Pekka Enberg
  0 siblings, 1 reply; 23+ messages in thread
From: Oliver Neukum @ 2008-01-24 12:58 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Am Donnerstag, 24. Januar 2008 13:34:00 schrieb Pekka Enberg:
> Hi Oliver,
> 
> On Jan 24, 2008 2:24 PM, Oliver Neukum <oliver@neukum.org> wrote:
> > > Sure but the filesystems in fs/ are general purpose and they can be
> > > mounted on top of any block device (except for the in-memory ones like
> >
> > nfs, cifs, jffs, ...
> 
> But none of them mess around with *hardware*. Sure, you can split it
> in two: driver and filesystem but yet again, the latter is not general
> purpose at all. I think this is somewhat similar to spufs which is
> really hardware specific and thus not eligible for fs/.

So we put it into drivers/usb/misc
Does that change the code?

> On Jan 24, 2008 2:24 PM, Oliver Neukum <oliver@neukum.org> wrote:
> > > sysfs). Furthermore, the problem with iriverfs is that it assumes that
> > > there can be only one device plugged to the host. What we want is
> > > something like
> > >
> > >   $ mount -t iriverfs /dev/iriver0 /mnt/media
> > >
> > > Which can be accomplished with an USB driver in driver/usb/ that
> > > registers the special iriverfs.
> >
> > And what happens if you do
> > mount -t vfat /dev/iriver0 /mnt/media ?
> 
> If /dev/iriver0 is registered as a block device, we read the
> superblock but don't find a vfat filesystem and the mount fails as
> expected. As for
> 
>    mount -t iriverfs /dev/sd1 /mnt/media
> 
> we need to make sure file_system_type->get_sb() does something like
> what drivers/mtd/mtdsuper.c::get_sb_mtd() does to make sure we only
> let it mount if the block device is indeed an iriver player.

How do you make a block device on top of this device? It has no notion
of reading/writing arbitrary blocks. It operates on files.

	Regards
		Oliver


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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 12:58               ` Oliver Neukum
@ 2008-01-24 13:14                 ` Pekka Enberg
  0 siblings, 0 replies; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 13:14 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Wilco Beekhuizen, Greg KH, linux-kernel

Hi,

On Jan 24, 2008 2:58 PM, Oliver Neukum <oliver@neukum.org> wrote:
> So we put it into drivers/usb/misc
> Does that change the code?

Yes. It's assumes only one device is plugged in.

On Jan 24, 2008 2:58 PM, Oliver Neukum <oliver@neukum.org> wrote:
> How do you make a block device on top of this device? It has no notion
> of reading/writing arbitrary blocks. It operates on files.

So you don't make it a block device which is even simpler. Now
get_sb_bdev() will fail before attempting to read the superblock. In
iriverfs, we only need to check for USB_DEVICE_MAJOR and then look up
struct usb_device to make sure we're allowed to mount.

                        Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 11:19     ` Pekka Enberg
  2008-01-24 11:49       ` Oliver Neukum
@ 2008-01-24 16:44       ` Greg KH
  2008-01-24 17:06         ` Pekka Enberg
  1 sibling, 1 reply; 23+ messages in thread
From: Greg KH @ 2008-01-24 16:44 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, linux-kernel

On Thu, Jan 24, 2008 at 01:19:25PM +0200, Pekka Enberg wrote:
> Hi Wilco,
> 
> On Jan 24, 2008 12:05 PM, Wilco Beekhuizen <wilcobeekhuizen@gmail.com> wrote:
> > Most code is pretty ancient, I just manage it so it compiles with
> > recent kernels. Is there somehting exported that is similar to
> > usb_find_device?
> 
> The problem is that iriverfs shouldn't be calling usb_find_device() at
> all. What happens when you plug in two players to the same computer?
> AFAICT the whole thing should be a proper USB driver in drivers/usb/
> and not a "filesystem" in fs/.

No, that's not the problem.  The code should just be using
usb_register_driver() and then doing what it needs to do in the probe()
callback, like any other USB driver.

By calling usb_find_device() it allows more than one driver to talk to
the device at the same time, setting it up for some very bad things to
possibly happen to the device.

So a simple code change should be all that is needed to properly fix
this.

If you want, I can make up a patch, just point me at the version you
wish me to modify.

thanks,

greg k-h

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 16:44       ` Greg KH
@ 2008-01-24 17:06         ` Pekka Enberg
  2008-01-24 17:20           ` Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 17:06 UTC (permalink / raw)
  To: Greg KH; +Cc: Wilco Beekhuizen, linux-kernel

Hi Greg,

On Jan 24, 2008 6:44 PM, Greg KH <greg@kroah.com> wrote:
> No, that's not the problem.  The code should just be using
> usb_register_driver() and then doing what it needs to do in the probe()
> callback, like any other USB driver.
>
> By calling usb_find_device() it allows more than one driver to talk to
> the device at the same time, setting it up for some very bad things to
> possibly happen to the device.
>
> So a simple code change should be all that is needed to properly fix
> this.
>
> If you want, I can make up a patch, just point me at the version you
> wish me to modify.

As I already mentioned in private, the code is here:

http://www.init0.nl/iriverfs-r0.1.0.1-linux-2.6.23.patch.bz2

It's basically abusing the USB driver stack with a ->probe() function
that returns -ENODEV and doing device discovery at mount time. That,
however, is also broken as it assumes there's only one device plugged
in (we're not passing any device identifier to sys_mount).

So it's not a simple code change at all. Are there any datasheets
available for these things or is the current driver reverse
engineered?

                        Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 17:06         ` Pekka Enberg
@ 2008-01-24 17:20           ` Greg KH
  2008-01-24 17:42             ` Pekka Enberg
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2008-01-24 17:20 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, linux-kernel

On Thu, Jan 24, 2008 at 07:06:39PM +0200, Pekka Enberg wrote:
> Hi Greg,
> 
> On Jan 24, 2008 6:44 PM, Greg KH <greg@kroah.com> wrote:
> > No, that's not the problem.  The code should just be using
> > usb_register_driver() and then doing what it needs to do in the probe()
> > callback, like any other USB driver.
> >
> > By calling usb_find_device() it allows more than one driver to talk to
> > the device at the same time, setting it up for some very bad things to
> > possibly happen to the device.
> >
> > So a simple code change should be all that is needed to properly fix
> > this.
> >
> > If you want, I can make up a patch, just point me at the version you
> > wish me to modify.
> 
> As I already mentioned in private, the code is here:
> 
> http://www.init0.nl/iriverfs-r0.1.0.1-linux-2.6.23.patch.bz2
> 
> It's basically abusing the USB driver stack with a ->probe() function
> that returns -ENODEV and doing device discovery at mount time. That,
> however, is also broken as it assumes there's only one device plugged
> in (we're not passing any device identifier to sys_mount).

By returning -ENODEV, that still allows some other driver or user
through usbfs to come in and start talking to the device, while this
"driver" also touches it.  Not nice.

> So it's not a simple code change at all.

Just create a root directory for every device that is seen in the
probe() function.  That should be pretty simple to do.

thanks,

greg k-h

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 17:20           ` Greg KH
@ 2008-01-24 17:42             ` Pekka Enberg
  2008-01-24 18:03               ` Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 17:42 UTC (permalink / raw)
  To: Greg KH; +Cc: Wilco Beekhuizen, linux-kernel

Hi Greg,

On Jan 24, 2008 7:20 PM, Greg KH <greg@kroah.com> wrote:
> > So it's not a simple code change at all.
>
> Just create a root directory for every device that is seen in the
> probe() function.  That should be pretty simple to do.

Yeah, that would work but why do we want to mount all devices under
the same mount point? If you move device discovery to ->probe() it's
simple to have per-device mount points by overriding ->get_sb() to
check for USB_DEVICE_MAJOR and look up the actual device, no?
Otherwise you have to deal with device plug/unplug at filesystem
level...

                        Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 17:42             ` Pekka Enberg
@ 2008-01-24 18:03               ` Greg KH
  2008-01-24 19:25                 ` Pekka J Enberg
  2008-01-24 20:00                 ` Oliver Neukum
  0 siblings, 2 replies; 23+ messages in thread
From: Greg KH @ 2008-01-24 18:03 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Wilco Beekhuizen, linux-kernel

On Thu, Jan 24, 2008 at 07:42:20PM +0200, Pekka Enberg wrote:
> Hi Greg,
> 
> On Jan 24, 2008 7:20 PM, Greg KH <greg@kroah.com> wrote:
> > > So it's not a simple code change at all.
> >
> > Just create a root directory for every device that is seen in the
> > probe() function.  That should be pretty simple to do.
> 
> Yeah, that would work but why do we want to mount all devices under
> the same mount point? If you move device discovery to ->probe() it's
> simple to have per-device mount points by overriding ->get_sb() to
> check for USB_DEVICE_MAJOR and look up the actual device, no?
> Otherwise you have to deal with device plug/unplug at filesystem
> level...

Yes, you could do that (per device mount), but it might be confusing for
users to have to control things that way.

And the unplug issue at a filesystem level should be pretty trivial to
handle, we do it all the time in /proc and /sys and other virtual
filesystems (usbfs) with no problems.

thanks,

greg k-h

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 18:03               ` Greg KH
@ 2008-01-24 19:25                 ` Pekka J Enberg
  2008-01-24 19:57                   ` Oliver Neukum
  2008-01-24 20:00                 ` Oliver Neukum
  1 sibling, 1 reply; 23+ messages in thread
From: Pekka J Enberg @ 2008-01-24 19:25 UTC (permalink / raw)
  To: Greg KH; +Cc: Wilco Beekhuizen, linux-kernel

Hi Greg,

On Thu, Jan 24, 2008 at 07:42:20PM +0200, Pekka Enberg wrote:
> > Yeah, that would work but why do we want to mount all devices under
> > the same mount point? If you move device discovery to ->probe() it's
> > simple to have per-device mount points by overriding ->get_sb() to
> > check for USB_DEVICE_MAJOR and look up the actual device, no?
> > Otherwise you have to deal with device plug/unplug at filesystem
> > level...
 
On Thu, 24 Jan 2008, Greg KH wrote:
> Yes, you could do that (per device mount), but it might be confusing for
> users to have to control things that way.

Well, that's how it works for all other music players (especially ones 
that support USB storage natively). But anyway, here's a skeleton driver 
for what I was proposing in case someone is interested.

			Pekka

---
 drivers/usb/misc/Kconfig  |    6 
 drivers/usb/misc/Makefile |    1 
 drivers/usb/misc/iriver.c |  312 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 319 insertions(+)

Index: linux-2.6/drivers/usb/misc/iriver.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/usb/misc/iriver.c	2008-01-24 21:15:07.000000000 +0200
@@ -0,0 +1,312 @@
+#include <linux/kref.h>
+#include <linux/module.h>
+#include <linux/mount.h>
+#include <linux/namei.h>
+#include <linux/usb.h>
+
+#define USB_IRIVER_MINOR_BASE	128	/* FIXME: ask for one */
+
+#define IRIVER_VENDOR_ID	0x4102
+
+static struct usb_device_id iriver_table[] = {
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1001) },
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1003) },
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1005) },
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1007) },
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1008) },
+	{ USB_DEVICE(IRIVER_VENDOR_ID, 0x1010) },
+	{ }
+};
+MODULE_DEVICE_TABLE(usb, iriver_table);
+
+struct iriver_device {
+	struct usb_device	*udev;
+	struct usb_interface	*interface;
+	unsigned char		*bulk_in_buffer;
+	size_t			bulk_in_size;
+	__u8			bulk_in_endpoint_addr;
+	__u8			bulk_out_endpoint_addr;
+	struct mutex		mutex;
+	struct kref		kref;
+};
+#define to_iriver_dev(d) container_of(d, struct iriver_device, kref)
+
+static struct usb_class_driver iriver_class = {
+	.name =		"iriver%d",
+	.minor_base =	USB_IRIVER_MINOR_BASE,
+};
+
+static void iriver_delete(struct kref *kref)
+{
+	struct iriver_device *dev = to_iriver_dev(kref);
+
+	usb_put_dev(dev->udev);
+	kfree(dev);
+}
+
+static void iriver_disconnect(struct usb_interface *interface)
+{
+	struct iriver_device *dev;
+
+	dev = usb_get_intfdata(interface);
+	usb_set_intfdata(interface, NULL);
+
+	usb_deregister_dev(interface, &iriver_class);
+	kref_put(&dev->kref, iriver_delete);
+}
+
+static int iriver_probe(struct usb_interface *interface,
+			const struct usb_device_id *id)
+{
+	struct usb_host_interface *iface_desc;
+	struct iriver_device *dev;
+	int i, err;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+	kref_init(&dev->kref);
+	mutex_init(&dev->mutex);
+
+	dev->udev = usb_get_dev(interface_to_usbdev(interface));
+	dev->interface = interface;
+
+	iface_desc = interface->cur_altsetting;
+	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
+		struct usb_endpoint_descriptor *endpoint;
+
+		endpoint = &iface_desc->endpoint[i].desc;
+
+		if (!dev->bulk_in_endpoint_addr &&
+		    usb_endpoint_is_bulk_in(endpoint)) {
+			size_t buffer_size;
+
+			buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+			dev->bulk_in_size = buffer_size;
+			dev->bulk_in_endpoint_addr = endpoint->bEndpointAddress;
+			dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
+			if (!dev->bulk_in_buffer) {
+				err = -ENOMEM;
+				goto failed;
+			}
+		}
+
+		if (!dev->bulk_out_endpoint_addr &&
+		    usb_endpoint_is_bulk_out(endpoint))
+			dev->bulk_out_endpoint_addr = endpoint->bEndpointAddress;
+	}
+	if (!dev->bulk_in_endpoint_addr || !dev->bulk_out_endpoint_addr) {
+		err = -EINVAL;
+		goto failed;
+	}
+	usb_set_intfdata(interface, dev);
+
+	err = usb_register_dev(interface, &iriver_class);
+	if (err) {
+		usb_set_intfdata(interface, NULL);
+		goto failed;
+	}
+	return 0;
+failed:
+	if (dev)
+		kref_put(&dev->kref, iriver_delete);
+	return err;
+}
+
+static struct usb_driver iriver_driver = {
+	.name		= "iriver",
+	.probe		= iriver_probe,
+	.disconnect	= iriver_disconnect,
+	.id_table	= iriver_table,
+};
+
+#define IRIVERFS_MAGIC 0xdeadbeef
+#define IRIVERFS_BLOCK_SIZE 512
+#define IRIVERFS_BLOCK_BITS 9
+
+static int iriver_set_super(struct super_block *sb, void *data)
+{
+	sb->s_fs_info = data;
+	return set_anon_super(sb, data);
+}
+
+static struct iriver_device *iriver_sb_info(struct super_block *sb)
+{
+	return sb->s_fs_info;
+}
+
+static void iriver_kill_sb(struct super_block *sb)
+{
+	generic_shutdown_super(sb);
+}
+
+static int iriverfs_readdir(struct file *file, void *dirent, filldir_t filldir)
+{
+	struct dentry *dentry = file->f_dentry;
+	struct super_block *sb = dentry->d_sb;
+	struct iriver_device *dev;
+
+	dev = iriver_sb_info(sb);
+	mutex_lock(&dev->mutex);
+	/*
+	 *	TODO: Fill in the blank.
+	 */
+	mutex_unlock(&dev->mutex);
+	return dcache_readdir(file, dirent, filldir);
+}
+
+static struct file_operations iriverfs_dir_ops = {
+	.open		= dcache_dir_open,
+	.release	= dcache_dir_close,
+	.read		= generic_read_dir,
+	.readdir	= iriverfs_readdir,
+};
+
+static struct dentry *iriverfs_lookup(struct inode *dir,
+				      struct dentry *dentry,
+				      struct nameidata *nd)
+{
+	return NULL;
+}
+
+static struct inode_operations iriverfs_dir_inode_ops = {
+	.lookup		= iriverfs_lookup,
+};
+
+static struct inode *iriver_get_inode(struct super_block *sb, int mode)
+{
+	struct inode *inode = new_inode(sb);
+	if (inode) {
+		switch (mode & S_IFMT) {
+		case S_IFDIR:
+			inode->i_op = &iriverfs_dir_inode_ops;
+			inode->i_fop = &iriverfs_dir_ops;
+			break;
+		default:
+			BUG();
+		}
+	}
+	return inode;
+}
+
+static const struct super_operations iriverfs_ops = {
+	.drop_inode	= generic_delete_inode,
+};
+
+static int iriver_fill_super(struct super_block *sb, void *data, int silent)
+{
+	struct dentry *root;
+	struct inode *inode;
+	int err;
+
+	sb->s_maxbytes = MAX_LFS_FILESIZE;
+	sb->s_blocksize = IRIVERFS_BLOCK_SIZE;
+	sb->s_blocksize_bits = IRIVERFS_BLOCK_BITS;
+	sb->s_magic = IRIVERFS_MAGIC;
+	sb->s_op = &iriverfs_ops;
+
+	inode = iriver_get_inode(sb, S_IFDIR | 0755);
+	if (!inode)
+		return -ENOMEM;
+
+	root = d_alloc_root(inode);
+	if (!root) {
+		iput(inode);
+		err = -ENOMEM;
+	}
+	sb->s_root = root;
+
+	return 0;
+}
+
+static int iriver_get_sb(struct file_system_type *fs_type, int flags,
+			 const char *dev_name, void *data,
+			 struct vfsmount *mnt)
+{
+	struct usb_interface *interface;
+	struct iriver_device *dev;
+	struct super_block *sb;
+	struct nameidata nd;
+	unsigned minor;
+	int err;
+
+	if (!dev_name)
+		return -EINVAL;
+
+	err = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
+	if (err)
+		return err;
+
+	if (nd.mnt->mnt_flags & MNT_NODEV) {
+		err = -EACCES;
+		goto error;
+	}
+	if (imajor(nd.dentry->d_inode) != USB_DEVICE_MAJOR) {
+		err = -EINVAL;
+		goto error;
+	}
+	minor = iminor(nd.dentry->d_inode);
+	path_release(&nd);
+	interface = usb_find_interface(&iriver_driver, minor);
+	if (!interface) {
+		err = -ENODEV;
+		goto error;
+	}
+	dev = usb_get_intfdata(interface);
+	sb = sget(fs_type, NULL, iriver_set_super, dev);
+	if (IS_ERR(sb)) {
+		err = PTR_ERR(sb);
+		goto error;
+	}
+	if (sb->s_root) {
+		err = -EBUSY;
+		goto error;
+	}
+	sb->s_flags = flags;
+	err = iriver_fill_super(sb, data, flags & MS_SILENT ? 1 : 0);
+	if (err) {
+		up_write(&sb->s_umount);
+		deactivate_super(sb);
+		goto error;
+	}
+	sb->s_flags |= MS_ACTIVE;
+	return simple_set_mnt(mnt, sb);
+error:
+	path_release(&nd);
+	return err;
+}
+
+static struct file_system_type iriverfs_fs_type = {
+	.owner		= THIS_MODULE,
+	.name		= "iriverfs",
+	.get_sb		= iriver_get_sb,
+	.kill_sb	= iriver_kill_sb,
+	.fs_flags	= FS_REQUIRES_DEV,
+};
+
+static int __init iriver_init(void)
+{
+	int err;
+
+	err = usb_register(&iriver_driver);
+	if (err)
+		return err;
+
+	err = register_filesystem(&iriverfs_fs_type);
+	if (err) {
+		usb_deregister(&iriver_driver);
+		return err;
+	}
+	return 0;
+}
+
+static void __exit iriver_exit(void)
+{
+	unregister_filesystem(&iriverfs_fs_type);
+	usb_deregister(&iriver_driver);
+}
+
+module_init(iriver_init);
+module_exit(iriver_exit);
+
+MODULE_LICENSE("GPL");
Index: linux-2.6/drivers/usb/misc/Kconfig
===================================================================
--- linux-2.6.orig/drivers/usb/misc/Kconfig	2008-01-24 21:15:14.000000000 +0200
+++ linux-2.6/drivers/usb/misc/Kconfig	2008-01-24 21:16:22.000000000 +0200
@@ -269,3 +269,9 @@
 	  See <http://www.linux-usb.org/usbtest/> for more information,
 	  including sample test device firmware and "how to use it".
 
+config USB_IRIVER
+	tristate "iRiver iFP portable music player driver (DEVELOPMENT)"
+	depends on USB && EXPERIMENTAL
+	help
+	  This is a driver for the iRiver iFP portable music player.
+
Index: linux-2.6/drivers/usb/misc/Makefile
===================================================================
--- linux-2.6.orig/drivers/usb/misc/Makefile	2008-01-24 21:16:33.000000000 +0200
+++ linux-2.6/drivers/usb/misc/Makefile	2008-01-24 21:16:46.000000000 +0200
@@ -26,6 +26,7 @@
 obj-$(CONFIG_USB_TEST)		+= usbtest.o
 obj-$(CONFIG_USB_TRANCEVIBRATOR)	+= trancevibrator.o
 obj-$(CONFIG_USB_USS720)	+= uss720.o
+obj-$(CONFIG_IRIVER)		+= iriver.o
 
 obj-$(CONFIG_USB_SISUSBVGA)	+= sisusbvga/
 

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 19:25                 ` Pekka J Enberg
@ 2008-01-24 19:57                   ` Oliver Neukum
  2008-01-24 20:10                     ` Pekka Enberg
  0 siblings, 1 reply; 23+ messages in thread
From: Oliver Neukum @ 2008-01-24 19:57 UTC (permalink / raw)
  To: Pekka J Enberg; +Cc: Greg KH, Wilco Beekhuizen, linux-kernel

Am Donnerstag, 24. Januar 2008 20:25:35 schrieb Pekka J Enberg:
> Well, that's how it works for all other music players (especially ones 
> that support USB storage natively). But anyway, here's a skeleton driver 
> for what I was proposing in case someone is interested.
> 

Are you proposing to mount a _character_ device?

	Regards
		Oliver


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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 18:03               ` Greg KH
  2008-01-24 19:25                 ` Pekka J Enberg
@ 2008-01-24 20:00                 ` Oliver Neukum
  2008-01-24 20:26                   ` Pekka Enberg
  2008-01-24 20:28                   ` Greg KH
  1 sibling, 2 replies; 23+ messages in thread
From: Oliver Neukum @ 2008-01-24 20:00 UTC (permalink / raw)
  To: Greg KH; +Cc: Pekka Enberg, Wilco Beekhuizen, linux-kernel

Am Donnerstag, 24. Januar 2008 19:03:13 schrieb Greg KH:
> And the unplug issue at a filesystem level should be pretty trivial to
> handle, we do it all the time in /proc and /sys and other virtual
> filesystems (usbfs) with no problems.

A discussion about lifetime rules for objects in sysfs anyone? ;->

	Regards
		Oliver


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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 19:57                   ` Oliver Neukum
@ 2008-01-24 20:10                     ` Pekka Enberg
  0 siblings, 0 replies; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 20:10 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Greg KH, Wilco Beekhuizen, linux-kernel

Hi Oliver,

On Jan 24, 2008 9:57 PM, Oliver Neukum <oliver@neukum.org> wrote:
> Are you proposing to mount a _character_ device?

/me looks

Yeah, I am proposing to mount whatever usb_register_dev() pops up in
/dev (which indeed is a character device). Is that a problem?

                       Pekka

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 20:00                 ` Oliver Neukum
@ 2008-01-24 20:26                   ` Pekka Enberg
  2008-01-24 20:28                   ` Greg KH
  1 sibling, 0 replies; 23+ messages in thread
From: Pekka Enberg @ 2008-01-24 20:26 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Greg KH, Wilco Beekhuizen, linux-kernel

Hi,

On Jan 24, 2008 10:00 PM, Oliver Neukum <oliver@neukum.org> wrote:
> A discussion about lifetime rules for objects in sysfs anyone? ;->

Furthermore, you need to unmount all devices before you can unplug one of them.

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 20:00                 ` Oliver Neukum
  2008-01-24 20:26                   ` Pekka Enberg
@ 2008-01-24 20:28                   ` Greg KH
  2008-01-25  8:58                     ` Oliver Neukum
  1 sibling, 1 reply; 23+ messages in thread
From: Greg KH @ 2008-01-24 20:28 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Pekka Enberg, Wilco Beekhuizen, linux-kernel

On Thu, Jan 24, 2008 at 09:00:21PM +0100, Oliver Neukum wrote:
> Am Donnerstag, 24. Januar 2008 19:03:13 schrieb Greg KH:
> > And the unplug issue at a filesystem level should be pretty trivial to
> > handle, we do it all the time in /proc and /sys and other virtual
> > filesystems (usbfs) with no problems.
> 
> A discussion about lifetime rules for objects in sysfs anyone? ;->

The objects (kobjects) are now separate from the sysfs core internals,
so this should all be fixed up now :)

Anyway, sysfs is (hopefully) different from this filesystem, it should
be able to be done using all of the ramfs code, and no "special" backing
logic would be needed.  Like usbfs...

And if you see problems in the usbfs implementation with regards to
lifetime rules (becides the devices file), please let me know.

thanks,

greg k-h

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

* Re: [PATCH] Missing usb_find_device symbol from usb.c
  2008-01-24 20:28                   ` Greg KH
@ 2008-01-25  8:58                     ` Oliver Neukum
  0 siblings, 0 replies; 23+ messages in thread
From: Oliver Neukum @ 2008-01-25  8:58 UTC (permalink / raw)
  To: Greg KH; +Cc: Pekka Enberg, Wilco Beekhuizen, linux-kernel

Am Donnerstag, 24. Januar 2008 21:28:33 schrieb Greg KH:
> And if you see problems in the usbfs implementation with regards to
> lifetime rules (becides the devices file), please let me know.

All looks sane.

	Regards
		Oliver


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

end of thread, other threads:[~2008-01-25  8:56 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-22 19:18 [PATCH] Missing usb_find_device symbol from usb.c Wilco Beekhuizen
2008-01-22 22:08 ` Adrian Bunk
2008-01-24  1:37 ` Greg KH
2008-01-24 10:05   ` Wilco Beekhuizen
2008-01-24 11:19     ` Pekka Enberg
2008-01-24 11:49       ` Oliver Neukum
2008-01-24 11:52         ` Pekka Enberg
2008-01-24 12:24           ` Oliver Neukum
2008-01-24 12:34             ` Pekka Enberg
2008-01-24 12:58               ` Oliver Neukum
2008-01-24 13:14                 ` Pekka Enberg
2008-01-24 16:44       ` Greg KH
2008-01-24 17:06         ` Pekka Enberg
2008-01-24 17:20           ` Greg KH
2008-01-24 17:42             ` Pekka Enberg
2008-01-24 18:03               ` Greg KH
2008-01-24 19:25                 ` Pekka J Enberg
2008-01-24 19:57                   ` Oliver Neukum
2008-01-24 20:10                     ` Pekka Enberg
2008-01-24 20:00                 ` Oliver Neukum
2008-01-24 20:26                   ` Pekka Enberg
2008-01-24 20:28                   ` Greg KH
2008-01-25  8:58                     ` Oliver Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).