X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=net%2Firda%2Firias_object.c;h=99ebb96f13869868bba080779354390c3284f5a9;hb=13bad37b04c779d98983307a27f97e9caa36f9b1;hp=a154b1d71c0f8d9af8e0f0c429886c5cdbe8b44c;hpb=0da974f4f303a6842516b764507e3c0a03f41e5a;p=safe%2Fjmp%2Flinux-2.6 diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c index a154b1d..99ebb96 100644 --- a/net/irda/irias_object.c +++ b/net/irda/irias_object.c @@ -16,7 +16,7 @@ * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * Neither Dag Brattli nor University of Tromsø admit liability nor + * Neither Dag Brattli nor University of Tromsø admit liability nor * provide warranty for any of this software. This material is * provided "AS-IS" and at no charge. * @@ -36,39 +36,6 @@ hashbin_t *irias_objects; */ struct ias_value irias_missing = { IAS_MISSING, 0, 0, 0, {0}}; -/* - * Function strndup (str, max) - * - * My own kernel version of strndup! - * - * Faster, check boundary... Jean II - */ -static char *strndup(char *str, int max) -{ - char *new_str; - int len; - - /* Check string */ - if (str == NULL) - return NULL; - /* Check length, truncate */ - len = strlen(str); - if(len > max) - len = max; - - /* Allocate new string */ - new_str = kmalloc(len + 1, GFP_ATOMIC); - if (new_str == NULL) { - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); - return NULL; - } - - /* Copy and truncate */ - memcpy(new_str, str, len); - new_str[len] = '\0'; - - return new_str; -} /* * Function ias_new_object (name, id) @@ -78,19 +45,25 @@ static char *strndup(char *str, int max) */ struct ias_object *irias_new_object( char *name, int id) { - struct ias_object *obj; + struct ias_object *obj; - IRDA_DEBUG( 4, "%s()\n", __FUNCTION__); + IRDA_DEBUG( 4, "%s()\n", __func__); obj = kzalloc(sizeof(struct ias_object), GFP_ATOMIC); if (obj == NULL) { IRDA_WARNING("%s(), Unable to allocate object!\n", - __FUNCTION__); + __func__); return NULL; } obj->magic = IAS_OBJECT_MAGIC; - obj->name = strndup(name, IAS_MAX_CLASSNAME); + obj->name = kstrndup(name, IAS_MAX_CLASSNAME, GFP_ATOMIC); + if (!obj->name) { + IRDA_WARNING("%s(), Unable to allocate name!\n", + __func__); + kfree(obj); + return NULL; + } obj->id = id; /* Locking notes : the attrib spinlock has lower precendence @@ -100,7 +73,8 @@ struct ias_object *irias_new_object( char *name, int id) if (obj->attribs == NULL) { IRDA_WARNING("%s(), Unable to allocate attribs!\n", - __FUNCTION__); + __func__); + kfree(obj->name); kfree(obj); return NULL; } @@ -160,7 +134,7 @@ int irias_delete_object(struct ias_object *obj) node = hashbin_remove_this(irias_objects, (irda_queue_t *) obj); if (!node) IRDA_DEBUG( 0, "%s(), object already removed!\n", - __FUNCTION__); + __func__); /* Destroy */ __irias_delete_object(obj); @@ -294,7 +268,7 @@ int irias_object_change_attribute(char *obj_name, char *attrib_name, /* Find object */ obj = hashbin_lock_find(irias_objects, 0, obj_name); if (obj == NULL) { - IRDA_WARNING("%s: Unable to find object: %s\n", __FUNCTION__, + IRDA_WARNING("%s: Unable to find object: %s\n", __func__, obj_name); return -1; } @@ -306,14 +280,14 @@ int irias_object_change_attribute(char *obj_name, char *attrib_name, attrib = hashbin_find(obj->attribs, 0, attrib_name); if (attrib == NULL) { IRDA_WARNING("%s: Unable to find attribute: %s\n", - __FUNCTION__, attrib_name); + __func__, attrib_name); spin_unlock_irqrestore(&obj->attribs->hb_spinlock, flags); return -1; } if ( attrib->value->type != new_value->type) { IRDA_DEBUG( 0, "%s(), changing value type not allowed!\n", - __FUNCTION__); + __func__); spin_unlock_irqrestore(&obj->attribs->hb_spinlock, flags); return -1; } @@ -348,15 +322,24 @@ void irias_add_integer_attrib(struct ias_object *obj, char *name, int value, attrib = kzalloc(sizeof(struct ias_attrib), GFP_ATOMIC); if (attrib == NULL) { IRDA_WARNING("%s: Unable to allocate attribute!\n", - __FUNCTION__); + __func__); return; } attrib->magic = IAS_ATTRIB_MAGIC; - attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); + attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC); /* Insert value */ attrib->value = irias_new_integer_value(value); + if (!attrib->name || !attrib->value) { + IRDA_WARNING("%s: Unable to allocate attribute!\n", + __func__); + if (attrib->value) + irias_delete_value(attrib->value); + kfree(attrib->name); + kfree(attrib); + return; + } irias_add_attrib(obj, attrib, owner); } @@ -383,14 +366,23 @@ void irias_add_octseq_attrib(struct ias_object *obj, char *name, __u8 *octets, attrib = kzalloc(sizeof(struct ias_attrib), GFP_ATOMIC); if (attrib == NULL) { IRDA_WARNING("%s: Unable to allocate attribute!\n", - __FUNCTION__); + __func__); return; } attrib->magic = IAS_ATTRIB_MAGIC; - attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); + attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC); attrib->value = irias_new_octseq_value( octets, len); + if (!attrib->name || !attrib->value) { + IRDA_WARNING("%s: Unable to allocate attribute!\n", + __func__); + if (attrib->value) + irias_delete_value(attrib->value); + kfree(attrib->name); + kfree(attrib); + return; + } irias_add_attrib(obj, attrib, owner); } @@ -416,14 +408,23 @@ void irias_add_string_attrib(struct ias_object *obj, char *name, char *value, attrib = kzalloc(sizeof( struct ias_attrib), GFP_ATOMIC); if (attrib == NULL) { IRDA_WARNING("%s: Unable to allocate attribute!\n", - __FUNCTION__); + __func__); return; } attrib->magic = IAS_ATTRIB_MAGIC; - attrib->name = strndup(name, IAS_MAX_ATTRIBNAME); + attrib->name = kstrndup(name, IAS_MAX_ATTRIBNAME, GFP_ATOMIC); attrib->value = irias_new_string_value(value); + if (!attrib->name || !attrib->value) { + IRDA_WARNING("%s: Unable to allocate attribute!\n", + __func__); + if (attrib->value) + irias_delete_value(attrib->value); + kfree(attrib->name); + kfree(attrib); + return; + } irias_add_attrib(obj, attrib, owner); } @@ -441,7 +442,7 @@ struct ias_value *irias_new_integer_value(int integer) value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC); if (value == NULL) { - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); return NULL; } @@ -466,13 +467,19 @@ struct ias_value *irias_new_string_value(char *string) value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC); if (value == NULL) { - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); return NULL; } value->type = IAS_STRING; value->charset = CS_ASCII; - value->t.string = strndup(string, IAS_MAX_STRING); + value->t.string = kstrndup(string, IAS_MAX_STRING, GFP_ATOMIC); + if (!value->t.string) { + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); + kfree(value); + return NULL; + } + value->len = strlen(value->t.string); return value; @@ -491,7 +498,7 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len) value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC); if (value == NULL) { - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); return NULL; } @@ -501,13 +508,12 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len) len = IAS_MAX_OCTET_STRING; value->len = len; - value->t.oct_seq = kmalloc(len, GFP_ATOMIC); + value->t.oct_seq = kmemdup(octseq, len, GFP_ATOMIC); if (value->t.oct_seq == NULL){ - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); kfree(value); return NULL; } - memcpy(value->t.oct_seq, octseq , len); return value; } @@ -517,12 +523,11 @@ struct ias_value *irias_new_missing_value(void) value = kzalloc(sizeof(struct ias_value), GFP_ATOMIC); if (value == NULL) { - IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); return NULL; } value->type = IAS_MISSING; - value->len = 0; return value; } @@ -535,7 +540,7 @@ struct ias_value *irias_new_missing_value(void) */ void irias_delete_value(struct ias_value *value) { - IRDA_DEBUG(4, "%s()\n", __FUNCTION__); + IRDA_DEBUG(4, "%s()\n", __func__); IRDA_ASSERT(value != NULL, return;); @@ -553,7 +558,7 @@ void irias_delete_value(struct ias_value *value) kfree(value->t.oct_seq); break; default: - IRDA_DEBUG(0, "%s(), Unknown value type!\n", __FUNCTION__); + IRDA_DEBUG(0, "%s(), Unknown value type!\n", __func__); break; } kfree(value);