Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753490AbbFHXaG (ORCPT ); Mon, 8 Jun 2015 19:30:06 -0400 Received: from mail-lb0-f170.google.com ([209.85.217.170]:33362 "EHLO mail-lb0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932569AbbFHX1U (ORCPT ); Mon, 8 Jun 2015 19:27:20 -0400 From: Rasmus Villemoes To: Andrew Morton , Greg Kroah-Hartman Cc: Joe Perches , Al Viro , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/8] lib/kobject.c: Use strreplace Date: Tue, 9 Jun 2015 01:26:52 +0200 Message-Id: <1433806017-10823-5-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1433806017-10823-1-git-send-email-linux@rasmusvillemoes.dk> References: <1433806017-10823-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1412 Lines: 52 There's probably not many slashes in the name, but starting over when we see one feels wrong. Signed-off-by: Rasmus Villemoes --- v2: Original code relied on the const laundering done by strchr; v1 had a corresponding explicit (char*) cast. Avoid this altogether. lib/kobject.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/kobject.c b/lib/kobject.c index 3b841b97fccd..75ee63834fd1 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -257,23 +257,20 @@ static int kobject_add_internal(struct kobject *kobj) int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs) { - const char *old_name = kobj->name; char *s; if (kobj->name && !fmt) return 0; - kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); - if (!kobj->name) { - kobj->name = old_name; + s = kvasprintf(GFP_KERNEL, fmt, vargs); + if (!s) return -ENOMEM; - } /* ewww... some of these buggers have '/' in the name ... */ - while ((s = strchr(kobj->name, '/'))) - s[0] = '!'; + strreplace(s, '/', '!'); + kfree(kobj->name); + kobj->name = s; - kfree(old_name); return 0; } -- 2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/