From patchwork Tue Dec 10 16:22:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11282927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9BD714BD for ; Tue, 10 Dec 2019 16:23:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A185B207FF for ; Tue, 10 Dec 2019 16:23:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A185B207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2BDE36E14A; Tue, 10 Dec 2019 16:23:07 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C4076E14A; Tue, 10 Dec 2019 16:23:06 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 08:23:05 -0800 X-IronPort-AV: E=Sophos;i="5.69,300,1571727600"; d="scan'208";a="225196991" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 08:23:03 -0800 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Tue, 10 Dec 2019 17:22:43 +0100 Message-Id: <20191210162243.14966-1-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v2] lib/sysfs: Add support for getting boolean module parameters X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Boolean module parameters are exposed as "Y"/"N" strings, not 0/1. Make igt_sysfs_get_boolean() helper useful for getting their values. v2: Use case insensitive string compare and more compact style (Chris) Signed-off-by: Janusz Krzysztofik Reviewed-by: Chris Wilson --- I've made it still more compact by eliminating a goto, Chris, I hope your Reviewed-by: still applies. Thanks, Janusz lib/igt_sysfs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index c439944d..17d0ab80 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -474,11 +474,19 @@ bool igt_sysfs_set_u32(int dir, const char *attr, uint32_t value) */ bool igt_sysfs_get_boolean(int dir, const char *attr) { + char *buf; int result; - if (igt_sysfs_scanf(dir, attr, "%d", &result) != 1) + buf = igt_sysfs_get(dir, attr); + if (!buf) return false; + if (sscanf(buf, "%d", &result) != 1) { + /* kernel's param_get_bool() returns "Y"/"N" */ + result = !strcasecmp(buf, "Y"); + } + + free(buf); return result; }