linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-03  8:37 Bernhard Walle
  2011-02-03 16:56 ` Grant Likely
  0 siblings, 1 reply; 19+ messages in thread
From: Bernhard Walle @ 2011-02-03  8:37 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel, akpm, arnd

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..833e238 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -30,6 +30,7 @@
 #include <linux/errno.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/compat.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/spidev.h>
@@ -471,6 +472,16 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#else
+#define spidev_compat_ioctl NULL
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +554,7 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+	.compat_ioctl = spidev_compat_ioctl,
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-03  8:37 [PATCH] spi: spidev: Add 32 bit compat ioctl() Bernhard Walle
@ 2011-02-03 16:56 ` Grant Likely
  0 siblings, 0 replies; 19+ messages in thread
From: Grant Likely @ 2011-02-03 16:56 UTC (permalink / raw)
  To: Bernhard Walle; +Cc: dbrownell, spi-devel-general, linux-kernel, akpm, arnd

On Thu, Feb 03, 2011 at 09:37:18AM +0100, Bernhard Walle wrote:
> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> userspace applications can access SPI. As far as I can see all data
> structure are already prepared for that, so no additional conversion has
> to be done.
> 
> My use case is MIPS with N32 userspace ABI and toolchain, and that was
> also the platform where I tested it successfully (Cavium Octeon).
> 
> Signed-off-by: Bernhard Walle <walle@corscience.de>

Applied, thanks.

g.

> ---
>  drivers/spi/spidev.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
> index 4e6245e..833e238 100644
> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -30,6 +30,7 @@
>  #include <linux/errno.h>
>  #include <linux/mutex.h>
>  #include <linux/slab.h>
> +#include <linux/compat.h>
>  
>  #include <linux/spi/spi.h>
>  #include <linux/spi/spidev.h>
> @@ -471,6 +472,16 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  	return retval;
>  }
>  
> +#ifdef CONFIG_COMPAT
> +static long
> +spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> +{
> +	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> +}
> +#else
> +#define spidev_compat_ioctl NULL
> +#endif /* CONFIG_COMPAT */
> +
>  static int spidev_open(struct inode *inode, struct file *filp)
>  {
>  	struct spidev_data	*spidev;
> @@ -543,6 +554,7 @@ static const struct file_operations spidev_fops = {
>  	.write =	spidev_write,
>  	.read =		spidev_read,
>  	.unlocked_ioctl = spidev_ioctl,
> +	.compat_ioctl = spidev_compat_ioctl,
>  	.open =		spidev_open,
>  	.release =	spidev_release,
>  	.llseek =	no_llseek,
> -- 
> 1.7.1
> 

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02 14:15 ` Grant Likely
@ 2011-02-03  8:38   ` Bernhard Walle
  0 siblings, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-02-03  8:38 UTC (permalink / raw)
  To: Grant Likely; +Cc: dbrownell, spi-devel-general, linux-kernel, akpm, arnd

Am 02.02.2011 15:15, schrieb Grant Likely:
>>  static int spidev_open(struct inode *inode, struct file *filp)
>>  {
>>        struct spidev_data      *spidev;
>> @@ -543,6 +552,9 @@ static const struct file_operations spidev_fops = {
>>        .write =        spidev_write,
>>        .read =         spidev_read,
>>        .unlocked_ioctl = spidev_ioctl,
>> +#ifdef CONFIG_COMPAT
>> +       .compat_ioctl = spidev_compat_ioctl,
>> +#endif
> 
> Then the #ifdef/#endif can be dropped here which is tidier.

Ok, thanks, I resent the patch with that modification.


Regards,
Bernhard

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02 11:31 Bernhard Walle
  2011-02-02 12:18 ` Arnd Bergmann
@ 2011-02-02 14:15 ` Grant Likely
  2011-02-03  8:38   ` Bernhard Walle
  1 sibling, 1 reply; 19+ messages in thread
From: Grant Likely @ 2011-02-02 14:15 UTC (permalink / raw)
  To: Bernhard Walle; +Cc: dbrownell, spi-devel-general, linux-kernel, akpm, arnd

On Wed, Feb 2, 2011 at 4:31 AM, Bernhard Walle <walle@corscience.de> wrote:
> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> userspace applications can access SPI. As far as I can see all data
> structure are already prepared for that, so no additional conversion has
> to be done.
>
> My use case is MIPS with N32 userspace ABI and toolchain, and that was
> also the platform where I tested it successfully (Cavium Octeon).
>
> Signed-off-by: Bernhard Walle <walle@corscience.de>
> ---
>  drivers/spi/spidev.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
> index 4e6245e..f80503b 100644
> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -30,6 +30,7 @@
>  #include <linux/errno.h>
>  #include <linux/mutex.h>
>  #include <linux/slab.h>
> +#include <linux/compat.h>
>
>  #include <linux/spi/spi.h>
>  #include <linux/spi/spidev.h>
> @@ -471,6 +472,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>        return retval;
>  }
>
> +#ifdef CONFIG_COMPAT
> +static long
> +spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> +{
> +       return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> +}
> +#endif /* CONFIG_COMPAT */

If you do the following...
+#else /* CONFIG_COMPAT */
+#define spidev_compat_ioctl NULL
+#endif /* CONFIG_COMPAT */

> +
>  static int spidev_open(struct inode *inode, struct file *filp)
>  {
>        struct spidev_data      *spidev;
> @@ -543,6 +552,9 @@ static const struct file_operations spidev_fops = {
>        .write =        spidev_write,
>        .read =         spidev_read,
>        .unlocked_ioctl = spidev_ioctl,
> +#ifdef CONFIG_COMPAT
> +       .compat_ioctl = spidev_compat_ioctl,
> +#endif

Then the #ifdef/#endif can be dropped here which is tidier.

g.

>        .open =         spidev_open,
>        .release =      spidev_release,
>        .llseek =       no_llseek,
> --
> 1.7.1
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02  9:37   ` Arnd Bergmann
  2011-02-02 10:56     ` Bernhard Walle
@ 2011-02-02 14:12     ` Grant Likely
  1 sibling, 0 replies; 19+ messages in thread
From: Grant Likely @ 2011-02-02 14:12 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Bernhard Walle, dbrownell, spi-devel-general, linux-kernel, akpm

On Wed, Feb 2, 2011 at 2:37 AM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Wednesday 02 February 2011, Grant Likely wrote:
>> On Tue, Feb 01, 2011 at 10:02:46AM +0100, Bernhard Walle wrote:
>> > Add the compat_ioctl for operations on /dev/spi* so that 32 bit
>> > userspace applications can access SPI. As far as I can see all data
>> > structure are already prepared for that, so no additional conversion has
>> > to be done.
>> >
>> > My use case is MIPS with N32 userspace ABI and toolchain, and that was
>> > also the platform where I tested it successfully (Cavium Octeon).
>> >
>> > Signed-off-by: Bernhard Walle <walle@corscience.de>
>>
>> Arnd, can you please give your opinion on this one?  I haven't fully
>> got my head around the subtleties of 32/64 bit file_operations.
>
> The patch is correct on everything except s390, which does not have SPI.
> The only thing that is missing for s390 is a pointer conversion of the ioctl
> argument, like:
>
> static long
> compat_spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> {
>        return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> }
>
> Some years ago, I proposed adding a common
>
> #ifdef CONFIG_COMPAT
> long generic_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> {
>        if (!file->unlocked_ioctl)
>                return -ENOTTY;
>        return filp->f_ops->unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> }
> #else
> #define generic_compat_ioctl NULL
> #endif
>
> for this purpose, but it never made it in. Maybe I should try again.

I'd like to see that go in too.  If you can implement it for the
2.6.39, then I'd like to see this patch rebased on top of it.

g.

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02 11:31 Bernhard Walle
@ 2011-02-02 12:18 ` Arnd Bergmann
  2011-02-02 14:15 ` Grant Likely
  1 sibling, 0 replies; 19+ messages in thread
From: Arnd Bergmann @ 2011-02-02 12:18 UTC (permalink / raw)
  To: Bernhard Walle
  Cc: dbrownell, grant.likely, spi-devel-general, linux-kernel, akpm

On Wednesday 02 February 2011, Bernhard Walle wrote:
> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> userspace applications can access SPI. As far as I can see all data
> structure are already prepared for that, so no additional conversion has
> to be done.
> 
> My use case is MIPS with N32 userspace ABI and toolchain, and that was
> also the platform where I tested it successfully (Cavium Octeon).
> 
> Signed-off-by: Bernhard Walle <walle@corscience.de>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02 11:15 ` Arnd Bergmann
@ 2011-02-02 11:32   ` Bernhard Walle
  0 siblings, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-02-02 11:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: dbrownell, grant.likely, spi-devel-general, linux-kernel, akpm

Am 02.02.2011 12:15, schrieb Arnd Bergmann:
> On Wednesday 02 February 2011, Bernhard Walle wrote:
>> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
>> userspace applications can access SPI. As far as I can see all data
>> structure are already prepared for that, so no additional conversion has
>> to be done.
>>
>> My use case is MIPS with N32 userspace ABI and toolchain, and that was
>> also the platform where I tested it successfully (Cavium Octeon).
>>
>> Signed-off-by: Bernhard Walle <walle@corscience.de>
> 
> I think you now need to #include <linux/compat.h> as well, to get the
> definition of compat_ptr(). Otherwise looks good.

It compiled on my MIPS test environment without that include, but I
adjusted the patch and posted again.

Thanks for reviewing, Arnd!


Regards,
Bernhard

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-02 11:31 Bernhard Walle
  2011-02-02 12:18 ` Arnd Bergmann
  2011-02-02 14:15 ` Grant Likely
  0 siblings, 2 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-02-02 11:31 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel, akpm, arnd

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..f80503b 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -30,6 +30,7 @@
 #include <linux/errno.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/compat.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/spidev.h>
@@ -471,6 +472,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +552,9 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = spidev_compat_ioctl,
+#endif
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-02 11:30 Bernhard Walle
  0 siblings, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-02-02 11:30 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel, akpm, arnd

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..95c3f10 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -471,6 +471,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +551,9 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = spidev_compat_ioctl,
+#endif
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02 10:57 Bernhard Walle
@ 2011-02-02 11:15 ` Arnd Bergmann
  2011-02-02 11:32   ` Bernhard Walle
  0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2011-02-02 11:15 UTC (permalink / raw)
  To: Bernhard Walle
  Cc: dbrownell, grant.likely, spi-devel-general, linux-kernel, akpm

On Wednesday 02 February 2011, Bernhard Walle wrote:
> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> userspace applications can access SPI. As far as I can see all data
> structure are already prepared for that, so no additional conversion has
> to be done.
> 
> My use case is MIPS with N32 userspace ABI and toolchain, and that was
> also the platform where I tested it successfully (Cavium Octeon).
> 
> Signed-off-by: Bernhard Walle <walle@corscience.de>

I think you now need to #include <linux/compat.h> as well, to get the
definition of compat_ptr(). Otherwise looks good.

	Arnd

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-02 10:57 Bernhard Walle
  2011-02-02 11:15 ` Arnd Bergmann
  0 siblings, 1 reply; 19+ messages in thread
From: Bernhard Walle @ 2011-02-02 10:57 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel, akpm, arnd

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..95c3f10 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -471,6 +471,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +551,9 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = spidev_compat_ioctl,
+#endif
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02  9:37   ` Arnd Bergmann
@ 2011-02-02 10:56     ` Bernhard Walle
  2011-02-02 14:12     ` Grant Likely
  1 sibling, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-02-02 10:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Grant Likely, dbrownell, spi-devel-general, linux-kernel, akpm

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]

Am 02.02.2011 10:37, schrieb Arnd Bergmann:
> On Wednesday 02 February 2011, Grant Likely wrote:
>> On Tue, Feb 01, 2011 at 10:02:46AM +0100, Bernhard Walle wrote:
>>> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
>>> userspace applications can access SPI. As far as I can see all data
>>> structure are already prepared for that, so no additional conversion has
>>> to be done.
>>>
>>> My use case is MIPS with N32 userspace ABI and toolchain, and that was
>>> also the platform where I tested it successfully (Cavium Octeon).
>>>
>>> Signed-off-by: Bernhard Walle <walle@corscience.de>
>>
>> Arnd, can you please give your opinion on this one?  I haven't fully
>> got my head around the subtleties of 32/64 bit file_operations.
> 
> The patch is correct on everything except s390, which does not have SPI.
> The only thing that is missing for s390 is a pointer conversion of the ioctl
> argument, like:
> 
> static long     
> compat_spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> {
> 	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> }

Thanks for the input. I modified my patch and sent it again.


Regards,
Bernhard


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 900 bytes --]

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-02 10:56 y
  0 siblings, 0 replies; 19+ messages in thread
From: y @ 2011-02-02 10:56 UTC (permalink / raw)
  To: dbrownell, grant.likely
  Cc: spi-devel-general, linux-kernel, akpm, arnd, Bernhard Walle

From: Bernhard Walle <walle@corscience.de>

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..95c3f10 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -471,6 +471,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +551,9 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = spidev_compat_ioctl,
+#endif
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-02 10:56 Unknown, y
  0 siblings, 0 replies; 19+ messages in thread
From: Unknown, y @ 2011-02-02 10:56 UTC (permalink / raw)
  To: dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f,
	grant.likely-s3s/WqlpOiPyB63q8FvJNQ
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, Bernhard Walle,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, arnd-r2nGTMty4D4

From: Bernhard Walle <walle-pDveNdigDaDu9UdzE1sIFA@public.gmane.org>

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle-pDveNdigDaDu9UdzE1sIFA@public.gmane.org>
---
 drivers/spi/spidev.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..95c3f10 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -471,6 +471,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return retval;
 }
 
+#ifdef CONFIG_COMPAT
+static long
+spidev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif /* CONFIG_COMPAT */
+
 static int spidev_open(struct inode *inode, struct file *filp)
 {
 	struct spidev_data	*spidev;
@@ -543,6 +551,9 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = spidev_compat_ioctl,
+#endif
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-02  4:39 ` Grant Likely
@ 2011-02-02  9:37   ` Arnd Bergmann
  2011-02-02 10:56     ` Bernhard Walle
  2011-02-02 14:12     ` Grant Likely
  0 siblings, 2 replies; 19+ messages in thread
From: Arnd Bergmann @ 2011-02-02  9:37 UTC (permalink / raw)
  To: Grant Likely
  Cc: Bernhard Walle, dbrownell, spi-devel-general, linux-kernel, akpm

On Wednesday 02 February 2011, Grant Likely wrote:
> On Tue, Feb 01, 2011 at 10:02:46AM +0100, Bernhard Walle wrote:
> > Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> > userspace applications can access SPI. As far as I can see all data
> > structure are already prepared for that, so no additional conversion has
> > to be done.
> > 
> > My use case is MIPS with N32 userspace ABI and toolchain, and that was
> > also the platform where I tested it successfully (Cavium Octeon).
> > 
> > Signed-off-by: Bernhard Walle <walle@corscience.de>
> 
> Arnd, can you please give your opinion on this one?  I haven't fully
> got my head around the subtleties of 32/64 bit file_operations.

The patch is correct on everything except s390, which does not have SPI.
The only thing that is missing for s390 is a pointer conversion of the ioctl
argument, like:

static long     
compat_spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
	return spidev_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
}

Some years ago, I proposed adding a common

#ifdef CONFIG_COMPAT
long generic_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
	if (!file->unlocked_ioctl)
		return -ENOTTY;
	return filp->f_ops->unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
}
#else
#define generic_compat_ioctl NULL
#endif

for this purpose, but it never made it in. Maybe I should try again.

	Arnd

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

* Re: [PATCH] spi: spidev: Add 32 bit compat ioctl()
  2011-02-01  9:02 Bernhard Walle
@ 2011-02-02  4:39 ` Grant Likely
  2011-02-02  9:37   ` Arnd Bergmann
  0 siblings, 1 reply; 19+ messages in thread
From: Grant Likely @ 2011-02-02  4:39 UTC (permalink / raw)
  To: Bernhard Walle, arnd; +Cc: dbrownell, spi-devel-general, linux-kernel, akpm

On Tue, Feb 01, 2011 at 10:02:46AM +0100, Bernhard Walle wrote:
> Add the compat_ioctl for operations on /dev/spi* so that 32 bit
> userspace applications can access SPI. As far as I can see all data
> structure are already prepared for that, so no additional conversion has
> to be done.
> 
> My use case is MIPS with N32 userspace ABI and toolchain, and that was
> also the platform where I tested it successfully (Cavium Octeon).
> 
> Signed-off-by: Bernhard Walle <walle@corscience.de>

Arnd, can you please give your opinion on this one?  I haven't fully
got my head around the subtleties of 32/64 bit file_operations.

Thanks,
g.

> ---
>  drivers/spi/spidev.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
> index 4e6245e..bb24ad8 100644
> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -543,6 +543,7 @@ static const struct file_operations spidev_fops = {
>  	.write =	spidev_write,
>  	.read =		spidev_read,
>  	.unlocked_ioctl = spidev_ioctl,
> +	.compat_ioctl = spidev_ioctl,
>  	.open =		spidev_open,
>  	.release =	spidev_release,
>  	.llseek =	no_llseek,
> -- 
> 1.7.1
> 

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-02-01  9:02 Bernhard Walle
  2011-02-02  4:39 ` Grant Likely
  0 siblings, 1 reply; 19+ messages in thread
From: Bernhard Walle @ 2011-02-01  9:02 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel, akpm

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..bb24ad8 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -543,6 +543,7 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+	.compat_ioctl = spidev_ioctl,
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2011-01-11 15:32 Bernhard Walle
  0 siblings, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2011-01-11 15:32 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 4e6245e..bb24ad8 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -543,6 +543,7 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+	.compat_ioctl = spidev_ioctl,
 	.open =		spidev_open,
 	.release =	spidev_release,
 	.llseek =	no_llseek,
-- 
1.7.1

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

* [PATCH] spi: spidev: Add 32 bit compat ioctl()
@ 2010-12-01 10:51 Bernhard Walle
  0 siblings, 0 replies; 19+ messages in thread
From: Bernhard Walle @ 2010-12-01 10:51 UTC (permalink / raw)
  To: dbrownell, grant.likely; +Cc: spi-devel-general, linux-kernel

Add the compat_ioctl for operations on /dev/spi* so that 32 bit
userspace applications can access SPI. As far as I can see all data
structure are already prepared for that, so no additional conversion has
to be done.

My use case is MIPS with N32 userspace ABI and toolchain, and that was
also the platform where I tested it successfully (Cavium Octeon).

Signed-off-by: Bernhard Walle <walle@corscience.de>
---
 drivers/spi/spidev.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index ea1bec3..d3d1155 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -543,6 +543,7 @@ static const struct file_operations spidev_fops = {
 	.write =	spidev_write,
 	.read =		spidev_read,
 	.unlocked_ioctl = spidev_ioctl,
+	.compat_ioctl = spidev_ioctl,
 	.open =		spidev_open,
 	.release =	spidev_release,
 };
-- 
1.7.1

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

end of thread, other threads:[~2011-02-03 16:56 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-03  8:37 [PATCH] spi: spidev: Add 32 bit compat ioctl() Bernhard Walle
2011-02-03 16:56 ` Grant Likely
  -- strict thread matches above, loose matches on Subject: below --
2011-02-02 11:31 Bernhard Walle
2011-02-02 12:18 ` Arnd Bergmann
2011-02-02 14:15 ` Grant Likely
2011-02-03  8:38   ` Bernhard Walle
2011-02-02 11:30 Bernhard Walle
2011-02-02 10:57 Bernhard Walle
2011-02-02 11:15 ` Arnd Bergmann
2011-02-02 11:32   ` Bernhard Walle
2011-02-02 10:56 Unknown, y
2011-02-02 10:56 y
2011-02-01  9:02 Bernhard Walle
2011-02-02  4:39 ` Grant Likely
2011-02-02  9:37   ` Arnd Bergmann
2011-02-02 10:56     ` Bernhard Walle
2011-02-02 14:12     ` Grant Likely
2011-01-11 15:32 Bernhard Walle
2010-12-01 10:51 Bernhard Walle

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).