diff mbox

[2/2] Input: joystick - use sizeof(VARIABLE) in documentation

Message ID 1387184235-20169-3-git-send-email-ospite@studenti.unina.it (mailing list archive)
State New, archived
Headers show

Commit Message

Antonio Ospite Dec. 16, 2013, 8:57 a.m. UTC
Use the preferred style sizeof(VARIABLE) instead of sizeof(TYPE) in the
joystick API documentation, Documentation/CodingStyle states that this
is the preferred style for allocations but using it elsewhere is good
too.

Also fix some errors like "sizeof(struct mybuffer)" which didn't mean
anything.

Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
---
 Documentation/input/joystick-api.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Dmitry Torokhov Dec. 16, 2013, 9:51 a.m. UTC | #1
Hi Antonio,

On Mon, Dec 16, 2013 at 09:57:15AM +0100, Antonio Ospite wrote:
> @@ -181,7 +181,7 @@ at a time using the typical read(2) functionality. For that, you would
>  replace the read above with something like
>  
>  	struct js_event mybuffer[0xff];
> -	int i = read (fd, mybuffer, sizeof(struct mybuffer));
> +	int i = read (fd, mybuffer, ARRAY_SIZE(mybuffer));
>  

This is wrong, as ARRAY_SIZE(mybuffer) would be 0xff and not the size of
buffer in bytes. I'll fix it up.

Thanks.
Antonio Ospite Dec. 16, 2013, 10:06 a.m. UTC | #2
On Mon, 16 Dec 2013 01:51:41 -0800
Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:

> Hi Antonio,
> 
> On Mon, Dec 16, 2013 at 09:57:15AM +0100, Antonio Ospite wrote:
> > @@ -181,7 +181,7 @@ at a time using the typical read(2) functionality. For that, you would
> >  replace the read above with something like
> >  
> >  	struct js_event mybuffer[0xff];
> > -	int i = read (fd, mybuffer, sizeof(struct mybuffer));
> > +	int i = read (fd, mybuffer, ARRAY_SIZE(mybuffer));
> >  
> 
> This is wrong, as ARRAY_SIZE(mybuffer) would be 0xff and not the size of
> buffer in bytes. I'll fix it up.
> 
> Thanks.

You're right of course, thank you.

Ciao,
   Antonio
diff mbox

Patch

diff --git a/Documentation/input/joystick-api.txt b/Documentation/input/joystick-api.txt
index f95f648..47e60a5 100644
--- a/Documentation/input/joystick-api.txt
+++ b/Documentation/input/joystick-api.txt
@@ -23,7 +23,7 @@  By default, the device is opened in blocking mode.
 ~~~~~~~~~~~~~~~~
 
 	struct js_event e;
-	read (fd, &e, sizeof(struct js_event));
+	read (fd, &e, sizeof(e));
 
 where js_event is defined as
 
@@ -34,8 +34,8 @@  where js_event is defined as
 		__u8 number;    /* axis/button number */
 	};
 
-If the read is successful, it will return sizeof(struct js_event), unless
-you wanted to read more than one event per read as described in section 3.1.
+If the read is successful, it will return sizeof(e), unless you wanted to read
+more than one event per read as described in section 3.1.
 
 
 2.1 js_event.type
@@ -144,7 +144,7 @@  all events on the queue (that is, until you get a -1).
 For example,
 
 	while (1) {
-		while (read (fd, &e, sizeof(struct js_event)) > 0) {
+		while (read (fd, &e, sizeof(e)) > 0) {
 	        	process_event (e);
 	   	}
 	   	/* EAGAIN is returned when the queue is empty */
@@ -181,7 +181,7 @@  at a time using the typical read(2) functionality. For that, you would
 replace the read above with something like
 
 	struct js_event mybuffer[0xff];
-	int i = read (fd, mybuffer, sizeof(struct mybuffer));
+	int i = read (fd, mybuffer, ARRAY_SIZE(mybuffer));
 
 In this case, read would return -1 if the queue was empty, or some
 other value in which the number of events read would be i /