Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2065654lqt; Sun, 21 Apr 2024 23:29:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYW6AawNRqqOBCkONFm7qKe5zfb+KayX3YZfRM7feOoWuWfyf3f6kAK2y1tOq5mdHkqAIIhfmeeKgse4U9P/ON24OtluC2+ZIoX56HXw== X-Google-Smtp-Source: AGHT+IHYGWyyJq+PeItZYPJjoqHmfAJ+kcpzloVjk/hL3093o+nGQoIsCbjHfIu5RAsSAzYVy5a8 X-Received: by 2002:a17:902:d4c7:b0:1e9:43c:d176 with SMTP id o7-20020a170902d4c700b001e9043cd176mr7992216plg.12.1713767382941; Sun, 21 Apr 2024 23:29:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713767382; cv=pass; d=google.com; s=arc-20160816; b=LDWa6GXD36GLbRovENfUDMj/bldwXyZ6QLnvtIZ/mFABz/BjS/IiJpFnRjYoAQ5yXW AwX5F9crRYTcRIKNcBQoG+6DhC99wlvPkovvDLao4XQYwSnCHnnIMKy2/B/x5wbaLAEz ZFlTva84yORJgNVXXWDtEODr+j5804Vs3A2fpdn2C0VncV1wUdkmmbiTPcXHv/onH+0h FaqKMu3+FsNRpDYmHaRpnA6QLVMAFSIjmLG7I0njiHP2uLVCil9l/bNC+ftU2zYdb/CM eDOc26O9YChH8qI52JLrFidzn3fjjwiTzKB1juwWvTfTD9cIpkcNV6fHMwLomYvagdxS 9zig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=jc5NIHXc95RILzH8MXXTKwjkUQz5iXFwYH0KXqtr1CM=; fh=sX5hgwdujapVrgqytR6yb3vQgwnXPV4qF04pzoM/Ffc=; b=RSH7snE78+R5qMeiin9samuSzjWoO3QTfQJ4uuuvUrzVsder44vk0wqXW/Da/vm65m 5fawvLQ9wbECNuYGTX3E53XviZHiwcbqSWhXo1BYLVA/A54Fh8RFKcqGqgfQJvyzul/I lhGp8Xxvt/Q/KNF4p0P7SzCcUTTRIBKMvuxyaDV2u5yT8Ksg0hG2xcSPqVGIO/EHBV3/ cQh4tjQjja4nkKZg2l4YkQoBgwfd2IlnuUHaIEXkNqtES+xxN5mQcWGLtiylIJTEzDDS VWeTDAXqxNYIToeq8O6ZrPDZlCP5txVBJ8HnNs24s7rGGk4PizR03o0Y8IXukZUmVkZO WqHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-152788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152788-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k6-20020a170902d58600b001e950a302d5si2876036plh.357.2024.04.21.23.29.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 23:29:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-152788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152788-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 88A4E282D32 for ; Mon, 22 Apr 2024 06:29:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E10B3FB94; Mon, 22 Apr 2024 06:29:28 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57BD8405F9; Mon, 22 Apr 2024 06:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713767367; cv=none; b=q69LoSD7vsMMQ/7sjwOurUv6BH6LxZo8qaRZrOmB4aW5Ucls+qtPhp8RJ4KUKVWEhmH/qKDNrSJ/+CDRXVuAo7qZjNy7blmYaQbwjNWTHpuf8NEihWlRLF7SHtNny49g1FlLQ9Eg6snJjtgNhnWUGMgCBEJRB0Rg+upYzTCGCB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713767367; c=relaxed/simple; bh=HlzQh948S8sIzvNyBVPCB6monqUovoXIO4DHiPWGYRw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jYmXwQP+HKX1VN5859K5NaQSA8s/tbN/pA7oz9pzjXC3vnqLTMLoxmKxEUDq81oveZx0Lqnkgs8aE95bfjlxpu0/zoaTEuR46XCouPTZVNejCVP24PWqsmtiWPVEoytf3CIUeDqEVG4H504RndlI5PJSfTGbtQSEqo6DMAPpzgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: a51326be007111ef9305a59a3cc225df-20240422 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:d05a343c-c0ca-4f1c-8c97-b7c21f260929,IP:10, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:-30 X-CID-INFO: VERSION:1.1.37,REQID:d05a343c-c0ca-4f1c-8c97-b7c21f260929,IP:10,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-30 X-CID-META: VersionHash:6f543d0,CLOUDID:75c230c35f4886e2cece48bf194582e1,BulkI D:240422142917Q175OXDX,BulkQuantity:0,Recheck:0,SF:66|24|17|19|44|102,TC:n il,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO GTI_C_BU, AMN_T1, AMN_GOOD, AMN_C_TI, AMN_C_BU ABX_MISS_RDNS X-UUID: a51326be007111ef9305a59a3cc225df-20240422 X-User: jiangyunshui@kylinos.cn Received: from kylin-pc.. [(112.64.161.44)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1917057899; Mon, 22 Apr 2024 14:29:17 +0800 From: yunshui To: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: corentin.chary@gmail.com, luke@ljones.dev, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, yunshui , Ai Chao Subject: [PATCH v2] platform/x86: asus-laptop: Use sysfs_emit() and sysfs_emit_at() to replace sprintf() Date: Mon, 22 Apr 2024 14:29:15 +0800 Message-Id: <20240422062915.3393480-1-jiangyunshui@kylinos.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As Documentation/filesystems/sysfs.rst suggested, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. Signed-off-by: yunshui Signed-off-by: Ai Chao --- drivers/platform/x86/asus-laptop.c | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 78c42767295a..ccb33d034e2a 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -852,8 +852,8 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr, * so we don't set eof to 1 */ - len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n"); - len += sprintf(page + len, "Model reference : %s\n", asus->name); + len += sysfs_emit_at(page, len, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n"); + len += sysfs_emit_at(page, len, "Model reference : %s\n", asus->name); /* * The SFUN method probably allows the original driver to get the list * of features supported by a given model. For now, 0x0100 or 0x0800 @@ -862,7 +862,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr, */ rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp); if (ACPI_SUCCESS(rv)) - len += sprintf(page + len, "SFUN value : %#x\n", + len += sysfs_emit_at(page, len, "SFUN value : %#x\n", (uint) temp); /* * The HWRS method return informations about the hardware. @@ -874,7 +874,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr, */ rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp); if (ACPI_SUCCESS(rv)) - len += sprintf(page + len, "HWRS value : %#x\n", + len += sysfs_emit_at(page, len, "HWRS value : %#x\n", (uint) temp); /* * Another value for userspace: the ASYM method returns 0x02 for @@ -885,25 +885,25 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr, */ rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp); if (ACPI_SUCCESS(rv)) - len += sprintf(page + len, "ASYM value : %#x\n", + len += sysfs_emit_at(page, len, "ASYM value : %#x\n", (uint) temp); if (asus->dsdt_info) { snprintf(buf, 16, "%d", asus->dsdt_info->length); - len += sprintf(page + len, "DSDT length : %s\n", buf); + len += sysfs_emit_at(page, len, "DSDT length : %s\n", buf); snprintf(buf, 16, "%d", asus->dsdt_info->checksum); - len += sprintf(page + len, "DSDT checksum : %s\n", buf); + len += sysfs_emit_at(page, len, "DSDT checksum : %s\n", buf); snprintf(buf, 16, "%d", asus->dsdt_info->revision); - len += sprintf(page + len, "DSDT revision : %s\n", buf); + len += sysfs_emit_at(page, len, "DSDT revision : %s\n", buf); snprintf(buf, 7, "%s", asus->dsdt_info->oem_id); - len += sprintf(page + len, "OEM id : %s\n", buf); + len += sysfs_emit_at(page, len, "OEM id : %s\n", buf); snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id); - len += sprintf(page + len, "OEM table id : %s\n", buf); + len += sysfs_emit_at(page, len, "OEM table id : %s\n", buf); snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision); - len += sprintf(page + len, "OEM revision : 0x%s\n", buf); + len += sysfs_emit_at(page, len, "OEM revision : 0x%s\n", buf); snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id); - len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); + len += sysfs_emit_at(page, len, "ASL comp vendor id : %s\n", buf); snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision); - len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); + len += sysfs_emit_at(page, len, "ASL comp revision : 0x%s\n", buf); } return len; @@ -933,7 +933,7 @@ static ssize_t ledd_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "0x%08x\n", asus->ledd_status); + return sysfs_emit(buf, "0x%08x\n", asus->ledd_status); } static ssize_t ledd_store(struct device *dev, struct device_attribute *attr, @@ -993,7 +993,7 @@ static ssize_t wlan_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS)); + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WL_RSTS)); } static ssize_t wlan_store(struct device *dev, struct device_attribute *attr, @@ -1022,7 +1022,7 @@ static ssize_t bluetooth_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS)); + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, BT_RSTS)); } static ssize_t bluetooth_store(struct device *dev, @@ -1052,7 +1052,7 @@ static ssize_t wimax_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS)); + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WM_RSTS)); } static ssize_t wimax_store(struct device *dev, struct device_attribute *attr, @@ -1081,7 +1081,7 @@ static ssize_t wwan_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS)); + return sysfs_emit(buf, "%d\n", asus_wireless_status(asus, WW_RSTS)); } static ssize_t wwan_store(struct device *dev, struct device_attribute *attr, @@ -1151,7 +1151,7 @@ static ssize_t ls_switch_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus->light_switch); + return sysfs_emit(buf, "%d\n", asus->light_switch); } static ssize_t ls_switch_store(struct device *dev, @@ -1182,7 +1182,7 @@ static ssize_t ls_level_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus->light_level); + return sysfs_emit(buf, "%d\n", asus->light_level); } static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr, @@ -1228,7 +1228,7 @@ static ssize_t ls_value_show(struct device *dev, struct device_attribute *attr, if (!err) err = pega_int_read(asus, PEGA_READ_ALS_L, &lo); if (!err) - return sprintf(buf, "%d\n", 10 * hi + lo); + return sysfs_emit(buf, "%d\n", 10 * hi + lo); return err; } static DEVICE_ATTR_RO(ls_value); @@ -1264,7 +1264,7 @@ static ssize_t gps_show(struct device *dev, struct device_attribute *attr, { struct asus_laptop *asus = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", asus_gps_status(asus)); + return sysfs_emit(buf, "%d\n", asus_gps_status(asus)); } static ssize_t gps_store(struct device *dev, struct device_attribute *attr, -- 2.34.1