X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=net%2Firda%2Firias_object.c;h=99ebb96f13869868bba080779354390c3284f5a9;hb=6e15cf04860074ad032e88c306bea656bbdd0f22;hp=4adaae242b9e44b422b46f1fe3b4fd8422db1b0d;hpb=5a84d159061d914c8dd4aa372ac6e9529c2be453;p=mv-sheeva.git diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c index 4adaae242b9..99ebb96f138 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, size_t 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) @@ -80,20 +47,20 @@ struct ias_object *irias_new_object( char *name, int id) { 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", - __FUNCTION__); + __func__); kfree(obj); return NULL; } @@ -106,7 +73,7 @@ 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; @@ -167,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); @@ -301,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; } @@ -313,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; } @@ -355,18 +322,18 @@ 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", - __FUNCTION__); + __func__); if (attrib->value) irias_delete_value(attrib->value); kfree(attrib->name); @@ -399,17 +366,17 @@ 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", - __FUNCTION__); + __func__); if (attrib->value) irias_delete_value(attrib->value); kfree(attrib->name); @@ -441,17 +408,17 @@ 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", - __FUNCTION__); + __func__); if (attrib->value) irias_delete_value(attrib->value); kfree(attrib->name); @@ -475,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; } @@ -500,15 +467,15 @@ 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", __FUNCTION__); + IRDA_WARNING("%s: Unable to kmalloc!\n", __func__); kfree(value); return NULL; } @@ -531,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; } @@ -543,7 +510,7 @@ struct ias_value *irias_new_octseq_value(__u8 *octseq , int len) 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; } @@ -556,7 +523,7 @@ 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; } @@ -573,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;); @@ -591,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);