Re: [PATCH 3/4] drivers/base: devres.c: use devm_kmemdup() from with devm_kstrdup()

From: Rob Jones
Date: Fri Jun 20 2014 - 05:20:36 EST



On 19/06/14 16:59, Joe Perches wrote:
On Thu, 2014-06-19 at 16:46 +0100, Rob Jones wrote:
Avoid code duplication by using devm_kmemdup() to copy data instead
of having a separate loop within devm_kstrdup().

Reviewed-by: Ian Molton <ian.molton@xxxxxxxxxxxxxxx>
Signed-off-by: Rob Jones <rob.jones@xxxxxxxxxxxxxxx>
[]
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
[]
@@ -802,17 +802,10 @@ EXPORT_SYMBOL_GPL(devm_kmalloc);
*/
char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
{
[]
+ return devm_kmemdup(dev, s, (strlen(s) + 1), gfp);
}
EXPORT_SYMBOL_GPL(devm_kstrdup);
Making this static inline in the header and dropping
EXPORT_SYMBOL_GPL might be smaller code.

static inline
char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
{
return devm_kmemdup(dev, s, strlen(s) + 1, gfp);
}


Is it wise not to check for (s == NULL)? Surely the behaviour of strlen(NULL) is undefined.

Consequently, I am, on balance, against making the function static inline. Given that inline is only a recommendation to the compiler, it may well not inline it anyway if the NULL test is present, in which case we would end up with a copy of the code in each module that uses it rather than a single, global, copy. If it didn't need the NULL test, I would agree that it would be best as a static inline but I think it does need it.

--
Rob Jones
Project Manager
Codethink Ltd
mailto:rob.jones@xxxxxxxxxxxxxxx
tel:+44 161 236 5575

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/