aboutsummaryrefslogtreecommitdiffstats
path: root/net/irda/irias_object.c
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@xensource.com>2007-07-17 21:37:02 -0400
committerJeremy Fitzhardinge <jeremy@goop.org>2007-07-18 11:47:39 -0400
commit1e66df3ee301209f4a38df097d7cc5cb9b367a3f (patch)
tree55beb2a342dbe08c0404f749e02808e3f09023ac /net/irda/irias_object.c
parent8b4a40809e5330c9da5d20107d693d92d73b31dc (diff)
add kstrndup
Add a kstrndup function, modelled on strndup. Like strndup this returns a string copied into its own allocated memory, but it copies no more than the specified number of bytes from the source. Remove private strndup() from irda code. Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> Signed-off-by: Chris Wright <chrisw@sous-sol.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Randy Dunlap <randy.dunlap@oracle.com> Cc: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Cc: Akinobu Mita <akinobu.mita@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@mandriva.com> Cc: Al Viro <viro@ftp.linux.org.uk> Cc: Panagiotis Issaris <takis@issaris.org> Cc: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Diffstat (limited to 'net/irda/irias_object.c')
-rw-r--r--net/irda/irias_object.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c
index 4adaae242b9e..cf302457097b 100644
--- a/net/irda/irias_object.c
+++ b/net/irda/irias_object.c
@@ -36,39 +36,6 @@ hashbin_t *irias_objects;
36 */ 36 */
37struct ias_value irias_missing = { IAS_MISSING, 0, 0, 0, {0}}; 37struct ias_value irias_missing = { IAS_MISSING, 0, 0, 0, {0}};
38 38
39/*
40 * Function strndup (str, max)
41 *
42 * My own kernel version of strndup!
43 *
44 * Faster, check boundary... Jean II
45 */
46static char *strndup(char *str, size_t max)
47{
48 char *new_str;
49 int len;
50
51 /* Check string */
52 if (str == NULL)
53 return NULL;
54 /* Check length, truncate */
55 len = strlen(str);
56 if(len > max)
57 len = max;
58
59 /* Allocate new string */
60 new_str = kmalloc(len + 1, GFP_ATOMIC);
61 if (new_str == NULL) {
62 IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__);
63 return NULL;
64 }
65
66 /* Copy and truncate */
67 memcpy(new_str, str, len);
68 new_str[len] = '\0';
69
70 return new_str;
71}
72 39
73/* 40/*
74 * Function ias_new_object (name, id) 41 * Function ias_new_object (name, id)
@@ -90,7 +57,7 @@ struct ias_object *irias_new_object( char *name, int id)
90 } 57 }
91 58
92 obj->magic = IAS_OBJECT_MAGIC; 59 obj->magic = IAS_OBJECT_MAGIC;
93 obj->name = strndup(name, IAS_MAX_CLASSNAME); 60 obj->name = kstrndup(name, IAS_MAX_CLASSNAME, GFP_ATOMIC);
94 if (!obj->name) { 61 if (!obj->name) {
95 IRDA_WARNING("%s(), Unable to allocate name!\n", 62 IRDA_WARNING("%s(), Unable to allocate name!\n",
96 __FUNCTION__); 63 __FUNCTION__);
@@ -360,7 +327,7 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value,
360 } 327 }
361 328
362 attrib->magic = IAS_ATTRIB_MAGIC; 329 attrib->magic = IAS_ATTRIB_MAGIC;
363 attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); 330 attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
364 331
365 /* Insert value */ 332 /* Insert value */
366 attrib->value = irias_new_integer_value(value); 333 attrib->value = irias_new_integer_value(value);
@@ -404,7 +371,7 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets,
404 } 371 }
405 372
406 attrib->magic = IAS_ATTRIB_MAGIC; 373 attrib->magic = IAS_ATTRIB_MAGIC;
407 attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); 374 attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
408 375
409 attrib->value = irias_new_octseq_value( octets, len); 376 attrib->value = irias_new_octseq_value( octets, len);
410 if (!attrib->name || !attrib->value) { 377 if (!attrib->name || !attrib->value) {
@@ -446,7 +413,7 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value,
446 } 413 }
447 414
448 attrib->magic = IAS_ATTRIB_MAGIC; 415 attrib->magic = IAS_ATTRIB_MAGIC;
449 attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); 416 attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC);
450 417
451 attrib->value = irias_new_string_value(value); 418 attrib->value = irias_new_string_value(value);
452 if (!attrib->name || !attrib->value) { 419 if (!attrib->name || !attrib->value) {
@@ -506,7 +473,7 @@ struct ias_value *irias_new_string_value(char *string)
506 473
507 value->type = IAS_STRING; 474 value->type = IAS_STRING;
508 value->charset = CS_ASCII; 475 value->charset = CS_ASCII;
509 value->t.string = strndup(string, IAS_MAX_STRING); 476 value->t.string = kstrndup(string, IAS_MAX_STRING, GFP_ATOMIC);
510 if (!value->t.string) { 477 if (!value->t.string) {
511 IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); 478 IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__);
512 kfree(value); 479 kfree(value);