Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5471279pxb; Wed, 26 Jan 2022 12:48:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEAFhtok8dp2NEt3CjUQEsF1jcaN1XRl0zJGGfspYA4D4h3ZAeNGqXY4anXcITqvDT7nyb X-Received: by 2002:a63:6f02:: with SMTP id k2mr512107pgc.218.1643230092523; Wed, 26 Jan 2022 12:48:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643230092; cv=none; d=google.com; s=arc-20160816; b=oj9KtWB63sL8rV/GmjuJ2AkdTASEIdNOVcJC2lFWzGts3gVCJlIq27JfwOscvGxhXw G90LXhcsfBvvCURetYbSus9q9JdQOcxY5F/qzO83EkxQ3X/776ka7dOR6cr7WKm8A2ZY 2oTsYVq/eWu2BundimoIVXGW/1zDyxTWfuuluL2eA9R7byXe/ldEx8UdaM/1ML81+V8L UIbB7pg94ikLZpLnjHKpecmPW5+OYU9foalpTzOGAb55OF5x8I22hKC6Ss+raQW6Doh4 Pn1XmoxWVqsg5RUN/kbYoqpMbaC3Khgm8052hOsOFZ9yZH9PApWowgdIkvqwJIvuosBY U6Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SjCU6HkRUbzFshvHmybXiVJQ+OAJerHzI8o9O3FAnqE=; b=ZDJl9k74dLlmskDizZjMxYvhuaCBvkkbVpJcXdkjzNWi6v6Nk3lmA+uEurCl8hXGfg 1T1stMzUBzPz92Kn0FmB7VI8/vd0Z4Fs68tPR9imImoaWzuIyKZ9Ezt38YMGIulRJ2qe FDTk7kNWvNFOXCWZITezfas56EKLRYDfNPurhdWsm66YnCKD0WS30XYQLy/5c5pptlX8 FcgjqKEoJFZUl21ldXEelUqR6ZP91yD97Xucbr1oYuXbfO+PgilSiDt8inbPTVsqczxf rFHWHdS98LDze63ttRY9IhQ1QIJm0EQdFBygyF6cxjriGWSwKJh9JYo7Zpm7cvnnUm+X gmFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=azB3zvlR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si271478pgq.150.2022.01.26.12.48.00; Wed, 26 Jan 2022 12:48:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=azB3zvlR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239258AbiAZJjf (ORCPT + 99 others); Wed, 26 Jan 2022 04:39:35 -0500 Received: from mga05.intel.com ([192.55.52.43]:9277 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239217AbiAZJja (ORCPT ); Wed, 26 Jan 2022 04:39:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643189970; x=1674725970; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=07WBSgMRDpJKqoyYch5hDAXQZYzth7c5ZCJjIGOcNFw=; b=azB3zvlRcNIUQ/XfmIITIq7BIvMDBmiwpaeZGw4eJ3YUZQolqsNyc3F2 y/+rvu9VHlZ3C16k4SK9TlWhzkfRnT6Wqp0MtdKUs9VEhx43CJnMMZww5 0+gN5HqeLJep2BbnT3Tf+bBDuatSwTGj0BmMISf/UAXvsekBF+q761xDG nGa7CpK9r/yDK8odq+hn7fwMJAkWN5BfTB6EH3Gcw29noL0QiTaZMraug 1oQKGZ6yIIZ+WnjsTxLYEuRWiWtdTV6Al4MsL/b6u3m/QI2Ul54qqznK6 isOiRa3XhHTVa3b3V5dlN2o27k6JHFaGHj1+0GSWudxutCG6DVWSeTNiQ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10238"; a="332869372" X-IronPort-AV: E=Sophos;i="5.88,317,1635231600"; d="scan'208";a="332869372" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2022 01:39:29 -0800 X-IronPort-AV: E=Sophos;i="5.88,317,1635231600"; d="scan'208";a="477433079" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2022 01:39:29 -0800 From: Lucas De Marchi To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-security-module@vger.kernel.org, nouveau@lists.freedesktop.org, netdev@vger.kernel.org Cc: Andy Shevchenko , Jani Nikula , Daniel Vetter , Alex Deucher , Andrew Morton , Andy Shevchenko , Ben Skeggs , =?UTF-8?q?Christian=20K=C3=B6nig?= , Chris Wilson , Daniel Vetter , David Airlie , "David S. Miller" , Emma Anholt , Francis Laniel , Greg Kroah-Hartman , Harry Wentland , Jakub Kicinski , Jani Nikula , Joonas Lahtinen , Julia Lawall , Kentaro Takeda , Leo Li , Petr Mladek , Rahul Lakkireddy , Raju Rangoju , Rasmus Villemoes , Rodrigo Vivi , Sakari Ailus , Sergey Senozhatsky , Steven Rostedt , Vishal Kulkarni Subject: [PATCH v2 01/11] lib/string_helpers: Consolidate string helpers implementation Date: Wed, 26 Jan 2022 01:39:41 -0800 Message-Id: <20220126093951.1470898-2-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220126093951.1470898-1-lucas.demarchi@intel.com> References: <20220126093951.1470898-1-lucas.demarchi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a few implementations of string helpers in the tree like yesno() that just returns "yes" or "no" depending on a boolean argument. Those are helpful to output strings to the user or log. In order to consolidate them, prefix all of them str_ prefix to make it clear what they are about and avoid symbol clashes. Taking the commoon `val ? "yes" : "no"` implementation, quite a few users of open coded yesno() could later be converted to the new function: $ git grep '?\s*"yes"\s*' | wc -l 286 $ git grep '?\s*"no"\s*' | wc -l 20 The inlined function should keep the const strings local to each compilation unit, the same way it's now, thus not changing the current behavior. Signed-off-by: Lucas De Marchi Reviewed-by: Andy Shevchenko Acked-by: Jani Nikula Acked-by: Daniel Vetter --- include/linux/string_helpers.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 7a22921c9db7..4d72258d42fd 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -106,4 +106,24 @@ void kfree_strarray(char **array, size_t n); char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n); +static inline const char *str_yes_no(bool v) +{ + return v ? "yes" : "no"; +} + +static inline const char *str_on_off(bool v) +{ + return v ? "on" : "off"; +} + +static inline const char *str_enable_disable(bool v) +{ + return v ? "enable" : "disable"; +} + +static inline const char *str_enabled_disabled(bool v) +{ + return v ? "enabled" : "disabled"; +} + #endif -- 2.34.1