Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932729AbbFHX10 (ORCPT ); Mon, 8 Jun 2015 19:27:26 -0400 Received: from mail-la0-f53.google.com ([209.85.215.53]:34439 "EHLO mail-la0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932607AbbFHX1V (ORCPT ); Mon, 8 Jun 2015 19:27:21 -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 5/8] drivers/base/core.c: Use strreplace Date: Tue, 9 Jun 2015 01:26:53 +0200 Message-Id: <1433806017-10823-6-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: 1094 Lines: 39 This eliminates a little .text and avoids repeating the strchr call when we meet a '!' (which will happen at least once). Signed-off-by: Rasmus Villemoes --- v2: Avoid ugly (char *) cast. drivers/base/core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 21d13038534e..dafae6d2f7ac 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1303,12 +1303,11 @@ const char *device_get_devnode(struct device *dev, return dev_name(dev); /* replace '!' in the name with '/' */ - *tmp = kstrdup(dev_name(dev), GFP_KERNEL); - if (!*tmp) + s = kstrdup(dev_name(dev), GFP_KERNEL); + if (!s) return NULL; - while ((s = strchr(*tmp, '!'))) - s[0] = '/'; - return *tmp; + strreplace(s, '!', '/'); + return *tmp = s; } /** -- 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/