Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp585176pxj; Thu, 27 May 2021 07:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWRa8pgUaLN5XSwvZQM4GMSpwESI6RE8xQQXsO26NJhkiJF6E6QDNCwjKcu7FztpQntBUV X-Received: by 2002:a5d:8f81:: with SMTP id l1mr2895335iol.115.1622124871542; Thu, 27 May 2021 07:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622124871; cv=none; d=google.com; s=arc-20160816; b=sFU0L3rSvhaFQJnUdkCrn7584j2o4GYEM70pjT9Es0MHgVoS0CpqGKKVSHmYYUZXUJ lKvIs1zKZmFm0BhGS4RG5wlosScodAfJ0mvEJEdLE1mqXtQi3R3K7rxc1KJr6DDyqZQZ h9BCaXK7zcjG5XUyi6r2SJ39dXGIrwyawhYLpUL4lAEhuhcRdDL14/0yfkpPhcLS307V dU8T/amisV0EMMZQ5q9zWOen5IX/6tdVwlR+wb4Jygty9vIHapb6SxrQEuI8YUYqz0ac r/aEhHt53jT6dj6qMa7h8M+uvSgZ0sYZX2Hr0/+jBkVLlu/ILve/UaLkz+/OLN6XrpOe 76Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=/tvwgm5R88doo1x1CXMu7+auYus70QRSP2rrnIGbq4A=; b=R4JRXrd7QtYtDMsPSEdbYOzL4zNTQihN+/I6QZG6AJNIAmUrpeTWrdeKYtexHKUyJW wNQL+gVmEgGmZxayWfOjBuANNsQGDijcWYtx73oc+Tk3hxs7ypqYe+uZ5MHPOPNukxvr /29jdSNl8F2eWFdnII/S/QdAC6sVcWmyuidHRZB6H6h0UdlHQGjHLYtz6rwy0bvFWBqm qLeFvB/Ncu8SwRGiDxwknpD5jIAE7s5NoltzxZ3peNDbqHHiMAI4sZv6kWSiSnSGsida 2QuO1FbrrQBjESOwNIhnLSsYLJinE5bbQckyMf1EiSV3jNhiqGdPpzW+NllSu9XLQTxu CPYA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t3si2576656jaj.67.2021.05.27.07.14.15; Thu, 27 May 2021 07:14:31 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236304AbhE0ON1 (ORCPT + 99 others); Thu, 27 May 2021 10:13:27 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2439 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235342AbhE0ON0 (ORCPT ); Thu, 27 May 2021 10:13:26 -0400 Received: from dggeml751-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4FrV6f5n4vz673r; Thu, 27 May 2021 22:08:58 +0800 (CST) Received: from dggema769-chm.china.huawei.com (10.1.198.211) by dggeml751-chm.china.huawei.com (10.1.199.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 27 May 2021 22:11:51 +0800 Received: from localhost (10.174.179.215) by dggema769-chm.china.huawei.com (10.1.198.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 27 May 2021 22:11:51 +0800 From: YueHaibing To: , , , , CC: , YueHaibing Subject: [PATCH -next] kernel/cpu: use DEVICE_ATTR_*() macro Date: Thu, 27 May 2021 22:11:05 +0800 Message-ID: <20210527141105.2312-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggema769-chm.china.huawei.com (10.1.198.211) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use DEVICE_ATTR_*() helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read. Signed-off-by: YueHaibing --- kernel/cpu.c | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index e538518556f4..00ffe7f023bc 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2183,18 +2183,17 @@ int cpuhp_smt_enable(void) #endif #if defined(CONFIG_SYSFS) && defined(CONFIG_HOTPLUG_CPU) -static ssize_t show_cpuhp_state(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t state_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); return sprintf(buf, "%d\n", st->state); } -static DEVICE_ATTR(state, 0444, show_cpuhp_state, NULL); +static DEVICE_ATTR_RO(state); -static ssize_t write_cpuhp_target(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t target_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); struct cpuhp_step *sp; @@ -2232,19 +2231,17 @@ static ssize_t write_cpuhp_target(struct device *dev, return ret ? ret : count; } -static ssize_t show_cpuhp_target(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t target_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); return sprintf(buf, "%d\n", st->target); } -static DEVICE_ATTR(target, 0644, show_cpuhp_target, write_cpuhp_target); - +static DEVICE_ATTR_RW(target); -static ssize_t write_cpuhp_fail(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t fail_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); struct cpuhp_step *sp; @@ -2293,15 +2290,15 @@ static ssize_t write_cpuhp_fail(struct device *dev, return count; } -static ssize_t show_cpuhp_fail(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t fail_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id); return sprintf(buf, "%d\n", st->fail); } -static DEVICE_ATTR(fail, 0644, show_cpuhp_fail, write_cpuhp_fail); +static DEVICE_ATTR_RW(fail); static struct attribute *cpuhp_cpu_attrs[] = { &dev_attr_state.attr, @@ -2316,7 +2313,7 @@ static const struct attribute_group cpuhp_cpu_attr_group = { NULL }; -static ssize_t show_cpuhp_states(struct device *dev, +static ssize_t states_show(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t cur, res = 0; @@ -2335,7 +2332,7 @@ static ssize_t show_cpuhp_states(struct device *dev, mutex_unlock(&cpuhp_state_mutex); return res; } -static DEVICE_ATTR(states, 0444, show_cpuhp_states, NULL); +static DEVICE_ATTR_RO(states); static struct attribute *cpuhp_cpu_root_attrs[] = { &dev_attr_states.attr, @@ -2408,28 +2405,27 @@ static const char *smt_states[] = { [CPU_SMT_NOT_IMPLEMENTED] = "notimplemented", }; -static ssize_t -show_smt_control(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t control_show(struct device *dev, + struct device_attribute *attr, char *buf) { const char *state = smt_states[cpu_smt_control]; return snprintf(buf, PAGE_SIZE - 2, "%s\n", state); } -static ssize_t -store_smt_control(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t control_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { return __store_smt_control(dev, attr, buf, count); } -static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control); +static DEVICE_ATTR_RW(control); -static ssize_t -show_smt_active(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t active_show(struct device *dev, + struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active()); } -static DEVICE_ATTR(active, 0444, show_smt_active, NULL); +static DEVICE_ATTR_RO(active); static struct attribute *cpuhp_smt_attrs[] = { &dev_attr_control.attr, -- 2.17.1