Skip to contentSkip to conversation

media: video: pwc: Use kernel's simple_strtol()

PATCH Superseded Andy Shevchenko 3 participants 8 messages Sep 16, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: video: pwc: Use kernel's simple_strtol()

From: Andy Shevchenko <[email protected]>

Change own implementation of atoi() by simple_strtol(x, NULL, 10).

---
 drivers/media/video/pwc/pwc-if.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/media/video/pwc/pwc-if.c +3 -10
index f976df4..cb995c6 100644
@@ -68,6 +68,7 @@
 #endif
 #include <linux/vmalloc.h>
 #include <asm/io.h>
+#include <linux/kernel.h>		/* simple_strtol() */
 
 #include "pwc.h"
 #include "pwc-kiara.h"
@@ -1916,17 +1917,9 @@ disconnect_out:
 	unlock_kernel();
 }
 
-/* *grunt* We have to do atoi ourselves :-( */
-static int pwc_atoi(const char *s)
+static inline int pwc_atoi(const char *s)
 {
-	int k = 0;
-
-	k = 0;
-	while (*s != '\0' && *s >= '0' && *s <= '9') {
-		k = 10 * k + (*s - '0');
-		s++;
-	}
-	return k;
+	return (int)simple_strtol(s, NULL, 10);
 }
 
 
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 3 lines · Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Change own implementation of atoi() by simple_strtol(x, NULL, 10).

Why did you keep the wrapper itself then ?

Quoted 35 lines
---
 drivers/media/video/pwc/pwc-if.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/media/video/pwc/pwc-if.c +3 -10
index f976df4..cb995c6 100644
@@ -68,6 +68,7 @@
 #endif
 #include <linux/vmalloc.h>
 #include <asm/io.h>
+#include <linux/kernel.h>		/* simple_strtol() */
 
 #include "pwc.h"
 #include "pwc-kiara.h"
@@ -1916,17 +1917,9 @@ disconnect_out:
 	unlock_kernel();
 }
 
-/* *grunt* We have to do atoi ourselves :-( */
-static int pwc_atoi(const char *s)
+static inline int pwc_atoi(const char *s)
 {
-	int k = 0;
-
-	k = 0;
-	while (*s != '\0' && *s >= '0' && *s <= '9') {
-		k = 10 * k + (*s - '0');
-		s++;
-	}
-	return k;
+	return (int)simple_strtol(s, NULL, 10);
 }
#2 lore raw
Quoted 2 lines · Andrey Panin
Quoted 1 line

Change own implementation of atoi() by simple_strtol(x, NULL, 10).

Why did you keep the wrapper itself then ?

I could change in all places, but it's only tiny inline function.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH v2 1/1 media: video: pwc: Use kernel's simple_strtol()

In reply to Andrey Panin

From: Andy Shevchenko <[email protected]>

Change own implementation of pwc_atoi() by simple_strtol(x, NULL, 10).

---
 drivers/media/video/pwc/pwc-if.c |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)
drivers/media/video/pwc/pwc-if.c +4 -16
index f976df4..0037a8c 100644
@@ -68,6 +68,7 @@
 #endif
 #include <linux/vmalloc.h>
 #include <asm/io.h>
+#include <linux/kernel.h>		/* simple_strtol() */
 
 #include "pwc.h"
 #include "pwc-kiara.h"
@@ -1916,19 +1917,6 @@ disconnect_out:
 	unlock_kernel();
 }
 
-/* *grunt* We have to do atoi ourselves :-( */
-static int pwc_atoi(const char *s)
-{
-	int k = 0;
-
-	k = 0;
-	while (*s != '\0' && *s >= '0' && *s <= '9') {
-		k = 10 * k + (*s - '0');
-		s++;
-	}
-	return k;
-}
-
 
 /*
  * Initialization code & module stuff
@@ -2078,13 +2066,13 @@ static int __init usb_pwc_init(void)
 				}
 				else {
 					/* No type or serial number specified, just a number. */
-					device_hint[i].device_node = pwc_atoi(s);
+					device_hint[i].device_node = (int)simple_strtol(s, NULL, 10);
 				}
 			}
 			else {
 				/* There's a colon, so we have at least a type and a device node */
-				device_hint[i].type = pwc_atoi(s);
-				device_hint[i].device_node = pwc_atoi(colon + 1);
+				device_hint[i].type = (int)simple_strtol(s, NULL, 10);
+				device_hint[i].device_node = (int)simple_strtol(colon + 1, NULL, 10);
 				if (*dot != '\0') {
 					/* There's a serial number as well */
 					int k;
Signature · 1 line
1.5.6.5
#4 lore raw

drivers/media/video/pwc/pwc-if.c static int __init usb_pwc_init(void) · line 2069

Quoted 6 lines · Andy Shevchenko
drivers/media/video/pwc/pwc-if.c +1 -1
@@ -2078,13 +2066,13 @@ static int __init usb_pwc_init(void)
                                }
                                else {
                                        /* No type or serial number specified, just a number. */
-                                       device_hint[i].device_node = pwc_atoi(s);
+                                       device_hint[i].device_node = (int)simple_strtol(s, NULL, 10);

What's with all the casting to int?

#5 lore raw

PATCH v3 1/1 media: video: pwc: Use kernel's simple_strtol()

From: Andy Shevchenko <[email protected]>

Change own implementation of pwc_atoi() by simple_strtol(x, NULL, 10).

---
 drivers/media/video/pwc/pwc-if.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)
drivers/media/video/pwc/pwc-if.c +7 -16
index f976df4..89b620f 100644
@@ -68,6 +68,7 @@
 #endif
 #include <linux/vmalloc.h>
 #include <asm/io.h>
+#include <linux/kernel.h>		/* simple_strtol() */
 
 #include "pwc.h"
 #include "pwc-kiara.h"
@@ -1916,19 +1917,6 @@ disconnect_out:
 	unlock_kernel();
 }
 
-/* *grunt* We have to do atoi ourselves :-( */
-static int pwc_atoi(const char *s)
-{
-	int k = 0;
-
-	k = 0;
-	while (*s != '\0' && *s >= '0' && *s <= '9') {
-		k = 10 * k + (*s - '0');
-		s++;
-	}
-	return k;
-}
-
 
 /*
  * Initialization code & module stuff
@@ -2078,13 +2066,16 @@ static int __init usb_pwc_init(void)
 				}
 				else {
 					/* No type or serial number specified, just a number. */
-					device_hint[i].device_node = pwc_atoi(s);
+					device_hint[i].device_node =
+						simple_strtol(s, NULL, 10);
 				}
 			}
 			else {
 				/* There's a colon, so we have at least a type and a device node */
-				device_hint[i].type = pwc_atoi(s);
-				device_hint[i].device_node = pwc_atoi(colon + 1);
+				device_hint[i].type =
+					simple_strtol(s, NULL, 10);
+				device_hint[i].device_node =
+					simple_strtol(colon + 1, NULL, 10);
 				if (*dot != '\0') {
 					/* There's a serial number as well */
 					int k;
Signature · 1 line
1.5.6.5
#7 lore raw
In reply to Pekka Enberg
Quoted 1 line · Pekka Enberg

What's with all the casting to int?

Yeah, you are right, they are redundant. See next iteration of the patch :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko