hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/lib/kstrtox.c
....@@ -14,11 +14,12 @@
1414 */
1515 #include <linux/ctype.h>
1616 #include <linux/errno.h>
17
-#include <linux/kernel.h>
18
-#include <linux/math64.h>
1917 #include <linux/export.h>
18
+#include <linux/kstrtox.h>
19
+#include <linux/math64.h>
2020 #include <linux/types.h>
2121 #include <linux/uaccess.h>
22
+
2223 #include "kstrtox.h"
2324
2425 const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
....@@ -122,8 +123,7 @@
122123 * @res: Where to write the result of the conversion on success.
123124 *
124125 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
125
- * Used as a replacement for the obsolete simple_strtoull. Return code must
126
- * be checked.
126
+ * Preferred over simple_strtoull(). Return code must be checked.
127127 */
128128 int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
129129 {
....@@ -146,8 +146,7 @@
146146 * @res: Where to write the result of the conversion on success.
147147 *
148148 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
149
- * Used as a replacement for the obsolete simple_strtoull. Return code must
150
- * be checked.
149
+ * Preferred over simple_strtoll(). Return code must be checked.
151150 */
152151 int kstrtoll(const char *s, unsigned int base, long long *res)
153152 {
....@@ -182,7 +181,7 @@
182181 rv = kstrtoull(s, base, &tmp);
183182 if (rv < 0)
184183 return rv;
185
- if (tmp != (unsigned long long)(unsigned long)tmp)
184
+ if (tmp != (unsigned long)tmp)
186185 return -ERANGE;
187186 *res = tmp;
188187 return 0;
....@@ -198,7 +197,7 @@
198197 rv = kstrtoll(s, base, &tmp);
199198 if (rv < 0)
200199 return rv;
201
- if (tmp != (long long)(long)tmp)
200
+ if (tmp != (long)tmp)
202201 return -ERANGE;
203202 *res = tmp;
204203 return 0;
....@@ -218,8 +217,7 @@
218217 * @res: Where to write the result of the conversion on success.
219218 *
220219 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
221
- * Used as a replacement for the obsolete simple_strtoull. Return code must
222
- * be checked.
220
+ * Preferred over simple_strtoul(). Return code must be checked.
223221 */
224222 int kstrtouint(const char *s, unsigned int base, unsigned int *res)
225223 {
....@@ -229,7 +227,7 @@
229227 rv = kstrtoull(s, base, &tmp);
230228 if (rv < 0)
231229 return rv;
232
- if (tmp != (unsigned long long)(unsigned int)tmp)
230
+ if (tmp != (unsigned int)tmp)
233231 return -ERANGE;
234232 *res = tmp;
235233 return 0;
....@@ -249,8 +247,7 @@
249247 * @res: Where to write the result of the conversion on success.
250248 *
251249 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
252
- * Used as a replacement for the obsolete simple_strtoull. Return code must
253
- * be checked.
250
+ * Preferred over simple_strtol(). Return code must be checked.
254251 */
255252 int kstrtoint(const char *s, unsigned int base, int *res)
256253 {
....@@ -260,7 +257,7 @@
260257 rv = kstrtoll(s, base, &tmp);
261258 if (rv < 0)
262259 return rv;
263
- if (tmp != (long long)(int)tmp)
260
+ if (tmp != (int)tmp)
264261 return -ERANGE;
265262 *res = tmp;
266263 return 0;
....@@ -275,7 +272,7 @@
275272 rv = kstrtoull(s, base, &tmp);
276273 if (rv < 0)
277274 return rv;
278
- if (tmp != (unsigned long long)(u16)tmp)
275
+ if (tmp != (u16)tmp)
279276 return -ERANGE;
280277 *res = tmp;
281278 return 0;
....@@ -290,7 +287,7 @@
290287 rv = kstrtoll(s, base, &tmp);
291288 if (rv < 0)
292289 return rv;
293
- if (tmp != (long long)(s16)tmp)
290
+ if (tmp != (s16)tmp)
294291 return -ERANGE;
295292 *res = tmp;
296293 return 0;
....@@ -305,7 +302,7 @@
305302 rv = kstrtoull(s, base, &tmp);
306303 if (rv < 0)
307304 return rv;
308
- if (tmp != (unsigned long long)(u8)tmp)
305
+ if (tmp != (u8)tmp)
309306 return -ERANGE;
310307 *res = tmp;
311308 return 0;
....@@ -320,7 +317,7 @@
320317 rv = kstrtoll(s, base, &tmp);
321318 if (rv < 0)
322319 return rv;
323
- if (tmp != (long long)(s8)tmp)
320
+ if (tmp != (s8)tmp)
324321 return -ERANGE;
325322 *res = tmp;
326323 return 0;