All of lore.kernel.org
 help / color / mirror / Atom feed
* SCSI vs MN10300: Can get_user() be given an array?
@ 2013-06-28 16:39 David Howells
  2013-06-28 18:16 ` James Bottomley
  0 siblings, 1 reply; 2+ messages in thread
From: David Howells @ 2013-06-28 16:39 UTC (permalink / raw)
  To: linux-arch, linux-scsi; +Cc: dhowells, Akira Takeuchi


The MN10300 arch is throwing up an error in the SCSI driver and I'm not sure
whether it needs fixing in the arch - in get_user() - or in the SCSI code.

The problem is this line in sg_scsi_ioctl():

	if (get_user(opcode, sic->data))

sic points to the following struct:

	typedef struct scsi_ioctl_command {
		unsigned int inlen;
		unsigned int outlen;
		unsigned char data[0];
	} Scsi_Ioctl_Command;

However, __get_user_check() on MN10300 does this:

	const __typeof__(ptr) __guc_ptr = (ptr);

which fails with:

	block/scsi_ioctl.c:450: error: invalid initializer

The question is what is SCSI actually asking get_user() to do?  As far as I
can tell, gcc thinks that it's being askied to declare some sort of array
here.

Should the SCSI driver be changed to:

	if (get_user(opcode, (unsigned char *)sic->data))

or should the MN10300 arch be changed to morph the array into a pointer,
perhaps with:

	const __typeof__(ptr[0])* __guc_ptr = (ptr);

or:

	const __typeof__(*ptr)* __guc_ptr = (ptr);

David

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

* Re: SCSI vs MN10300: Can get_user() be given an array?
  2013-06-28 16:39 SCSI vs MN10300: Can get_user() be given an array? David Howells
@ 2013-06-28 18:16 ` James Bottomley
  0 siblings, 0 replies; 2+ messages in thread
From: James Bottomley @ 2013-06-28 18:16 UTC (permalink / raw)
  To: David Howells; +Cc: linux-arch, linux-scsi, Akira Takeuchi

On Fri, 2013-06-28 at 17:39 +0100, David Howells wrote:
> The MN10300 arch is throwing up an error in the SCSI driver and I'm not sure
> whether it needs fixing in the arch - in get_user() - or in the SCSI code.
> 
> The problem is this line in sg_scsi_ioctl():
> 
> 	if (get_user(opcode, sic->data))
> 
> sic points to the following struct:
> 
> 	typedef struct scsi_ioctl_command {
> 		unsigned int inlen;
> 		unsigned int outlen;
> 		unsigned char data[0];
> 	} Scsi_Ioctl_Command;
> 
> However, __get_user_check() on MN10300 does this:
> 
> 	const __typeof__(ptr) __guc_ptr = (ptr);
> 
> which fails with:
> 
> 	block/scsi_ioctl.c:450: error: invalid initializer
> 
> The question is what is SCSI actually asking get_user() to do?  As far as I
> can tell, gcc thinks that it's being askied to declare some sort of array
> here.

I'm surprised you need to ask this.  by convention, an array of char is
usable as a pointer to char *.  The compiler therefore thinks this is a
legitimate conversion which doesn't need a cast:

	unsigned char *d = sic->data;

Therefore, sic->data should be usable as a char * pointer everywhere.

> Should the SCSI driver be changed to:
> 
> 	if (get_user(opcode, (unsigned char *)sic->data))

can we visit reality for a minute?  That proposal would require us to do
an explicit (unsigned char *) conversion everywhere we use an array as a
pointer value ... good grief, no!

> or should the MN10300 arch be changed to morph the array into a pointer,
> perhaps with:
> 
> 	const __typeof__(ptr[0])* __guc_ptr = (ptr);

Neither.  It should do what every other architecture does, which is:

	const __typeof__(*(ptr)) *__guc_ptr = (ptr);

James

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

end of thread, other threads:[~2013-06-28 18:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-28 16:39 SCSI vs MN10300: Can get_user() be given an array? David Howells
2013-06-28 18:16 ` James Bottomley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.