From patchwork Tue Dec 10 14:25:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11282595 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 ED6FF6C1 for ; Tue, 10 Dec 2019 14:33:04 +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 D16AD2077B for ; Tue, 10 Dec 2019 14:33:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D16AD2077B 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 74D366E8E7; Tue, 10 Dec 2019 14:33:04 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org X-Greylist: delayed 426 seconds by postgrey-1.36 at gabe; Tue, 10 Dec 2019 14:33:03 UTC Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB3F56E8E7; Tue, 10 Dec 2019 14:33:03 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 06:25:56 -0800 X-IronPort-AV: E=Sophos;i="5.69,300,1571727600"; d="scan'208";a="203201971" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 06:25:52 -0800 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Tue, 10 Dec 2019 15:25:31 +0100 Message-Id: <20191210142531.6447-1-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH i-g-t] 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: =?utf-8?q?Micha=C5=82_Czapli=C5=84ski?= , Jari Tahvanainen 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. Signed-off-by: Janusz Krzysztofik Cc: Chris Wilson --- lib/igt_sysfs.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index c439944d..c2b8291d 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -474,11 +474,23 @@ 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) + goto out; + + /* kernel's param_get_bool() returns "Y"/"N" */ + if (!strcmp(buf, "Y")) + result = true; + else + result = false; +out: + free(buf); return result; }