Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7418718imu; Mon, 3 Dec 2018 12:35:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vp72+MjMSx9hS6/wOAKTfifj9IWlmIqg6fDf4X42K6/ENsDxy1bgAb7xO7N+H5NKaqV4gM X-Received: by 2002:a63:9041:: with SMTP id a62mr14135468pge.163.1543869349739; Mon, 03 Dec 2018 12:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543869349; cv=none; d=google.com; s=arc-20160816; b=ezKYQ9jeiStLIHq+QOSJ6jQ5dfjEfIcr2K0wr1FQzWnvAaUL1+DgTuFfsfB11LQ49j EL4mntXFqnWUgcKB1faEyB9xSSksW7u8OsfqaIexwGcKdLdNj592BnJjwHM0Ijf5KfH6 nn/mvxH5fRCathQTfkhJNBKZ87QQCpjI7Hns7s2FYf9vRxe52nd3CbzYUvYDn4NkMdE+ j+cRvShmB5NwkEoRzz+hsgGg8YDbHbhYSvvWfBaoiMMUThmRBh0qqE3SbNN49j+cJrly wAWBaKjvtK9nev6ZAhCgaQuEkjTsLmYYFaXaGm7yYYcpcXQcEHXfPSt0LRflsYVaupwL fWzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=/H+DYF/gmReZwQWsv7MKq2jl03FrcNxhmAwYZyuixkU=; b=wHsf9QSpfH9A+cQ5lAd9PJBV1pwLQu7LQhK5LIa5tCOBNFkgclbq7jX2VTx5RYLqIV n3IImiCMsK9v6Jzwu4K37g24T0YRBKuqSxI010c5vh2Ue0Bo3CiyPlBZkFnchHkUAr9B 03d/JF1yyFgc9plL5v6fRBpIXjYNAikqcAKy9SetGwe7DkH4rdZxBy3dLPrYFn0RVz8o /SQP72c7UQ3yBgC5OWAf6vpDPahEyWLw0fR2l5c1fuXNZ+V2o6j7f+6yVvBZcV5wBg9n Q+Icofgo4HolyDcoxBu3tIduUWLyE6FftPvMuvLdl0SM162NR4f9iKynL27FUNruPmuO 98vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TnPg6RN5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h127si14476887pfe.204.2018.12.03.12.35.34; Mon, 03 Dec 2018 12:35:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TnPg6RN5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725961AbeLCUe5 (ORCPT + 99 others); Mon, 3 Dec 2018 15:34:57 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35426 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbeLCUe5 (ORCPT ); Mon, 3 Dec 2018 15:34:57 -0500 Received: by mail-ed1-f66.google.com with SMTP id x30so11981679edx.2 for ; Mon, 03 Dec 2018 12:34:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/H+DYF/gmReZwQWsv7MKq2jl03FrcNxhmAwYZyuixkU=; b=TnPg6RN5cfy5w80wcwv59bMweiOq4tGasbzQXkNu9GkmIKoegjwLEpf2tx52N7dy5H UMHVQaigSnOutrhDMVnorqDHDMokk9to7XOkBjZmjGm+OzxU+PwLyDCdQHGjTqaSVnAT QwadmriflQ1HeEeV8MwCniEB2Zuq/R4isQR+Rx063HwrebgulSYVh2ZvFzuOSJG6Alds OVkvVo8qrkR8Zd9YtXSeCBo1zf9eIhfSyEhcSPyrRnLvzEuj7+f3tnMuW4k4JOHZD3v8 yICoVspmNvRLEiQeMCejXysvQn2lS+iQyU+R4/Hy0MDtUYl5pCUeARyWgxBDE36S3eVp Efeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=/H+DYF/gmReZwQWsv7MKq2jl03FrcNxhmAwYZyuixkU=; b=PYmRhxN/hCheb4jom7nAwMpIFFUzB/OwtzUkf036WOgNR+QcrkDxAudG3oAiS3+uSz Kzamsh9vmj9J2sYzAtqP8BE3qmocqRN3J4uWjbmKiMldpNrWaN592RV0V8mb8Gn8fm3T 3FQYSqGb8/gPFfK+lYLnalGJrVL8tpU1DKDU9SYcsqhYp3qHRpLINKAy+/gPdyMgxeKP YmL810oH+H8A3BfnT4Pf18q/y3Muog09UpH5HISnauJDSm3RDhKe8WsfVyMYWG3E3Z7a enCBRuljPaEgt7fWSgoc6d2El+IR5lnzir6zhhxxjbSrkWdMlrQypXwkLJkHxgdUlqz4 FCUA== X-Gm-Message-State: AA+aEWbew3RuhXJM4uv9SWfd4prftieamAWYGSyULbD1rBs3zvm3BgF/ jiPlnWrPPhZjSJhouXJXQJE= X-Received: by 2002:a17:906:45d8:: with SMTP id z24-v6mr13712720ejq.19.1543869292534; Mon, 03 Dec 2018 12:34:52 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id i24sm3966217edq.0.2018.12.03.12.34.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Dec 2018 12:34:51 -0800 (PST) Date: Mon, 3 Dec 2018 20:34:50 +0000 From: Wei Yang To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Ingo Molnar , Pavel Tatashin , Oscar Salvador , Michal Hocko , Wei Yang Subject: Re: [PATCH v1] drivers/base/memory.c: Use DEVICE_ATTR_RO and friends Message-ID: <20181203203450.rjrpn2l4hpsjstfa@master> Reply-To: Wei Yang References: <20181203111611.10633-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181203111611.10633-1-david@redhat.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 03, 2018 at 12:16:11PM +0100, David Hildenbrand wrote: >Let's use the easier to read (and not mess up) variants: >- Use DEVICE_ATTR_RO >- Use DEVICE_ATTR_WO >- Use DEVICE_ATTR_RW >instead of the more generic DEVICE_ATTR() we're using right now. > >We have to rename most callback functions. By fixing the intendations we >can even save some LOCs. > >Cc: Greg Kroah-Hartman >Cc: "Rafael J. Wysocki" >Cc: Andrew Morton >Cc: Ingo Molnar >Cc: Pavel Tatashin >Cc: Oscar Salvador >Cc: Michal Hocko >Cc: Wei Yang >Signed-off-by: David Hildenbrand Looks good to me. Reviewed-by: Wei Yang >--- > drivers/base/memory.c | 79 ++++++++++++++++++++----------------------- > 1 file changed, 36 insertions(+), 43 deletions(-) > >diff --git a/drivers/base/memory.c b/drivers/base/memory.c >index 0c290f86ab20..c9c1ee564edb 100644 >--- a/drivers/base/memory.c >+++ b/drivers/base/memory.c >@@ -109,8 +109,8 @@ static unsigned long get_memory_block_size(void) > * uses. > */ > >-static ssize_t show_mem_start_phys_index(struct device *dev, >- struct device_attribute *attr, char *buf) >+static ssize_t phys_index_show(struct device *dev, >+ struct device_attribute *attr, char *buf) > { > struct memory_block *mem = to_memory_block(dev); > unsigned long phys_index; >@@ -122,8 +122,8 @@ static ssize_t show_mem_start_phys_index(struct device *dev, > /* > * Show whether the section of memory is likely to be hot-removable > */ >-static ssize_t show_mem_removable(struct device *dev, >- struct device_attribute *attr, char *buf) >+static ssize_t removable_show(struct device *dev, struct device_attribute *attr, >+ char *buf) > { > unsigned long i, pfn; > int ret = 1; >@@ -146,8 +146,8 @@ static ssize_t show_mem_removable(struct device *dev, > /* > * online, offline, going offline, etc. > */ >-static ssize_t show_mem_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 memory_block *mem = to_memory_block(dev); > ssize_t len = 0; >@@ -286,7 +286,7 @@ static int memory_subsys_online(struct device *dev) > return 0; > > /* >- * If we are called from store_mem_state(), online_type will be >+ * If we are called from state_store(), online_type will be > * set >= 0 Otherwise we were called from the device online > * attribute and need to set the online_type. > */ >@@ -315,9 +315,8 @@ static int memory_subsys_offline(struct device *dev) > return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); > } > >-static ssize_t >-store_mem_state(struct device *dev, >- struct device_attribute *attr, const char *buf, size_t count) >+static ssize_t state_store(struct device *dev, struct device_attribute *attr, >+ const char *buf, size_t count) > { > struct memory_block *mem = to_memory_block(dev); > int ret, online_type; >@@ -374,7 +373,7 @@ store_mem_state(struct device *dev, > * s.t. if I offline all of these sections I can then > * remove the physical device? > */ >-static ssize_t show_phys_device(struct device *dev, >+static ssize_t phys_device_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > struct memory_block *mem = to_memory_block(dev); >@@ -395,7 +394,7 @@ static void print_allowed_zone(char *buf, int nid, unsigned long start_pfn, > } > } > >-static ssize_t show_valid_zones(struct device *dev, >+static ssize_t valid_zones_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > struct memory_block *mem = to_memory_block(dev); >@@ -435,33 +434,31 @@ static ssize_t show_valid_zones(struct device *dev, > > return strlen(buf); > } >-static DEVICE_ATTR(valid_zones, 0444, show_valid_zones, NULL); >+static DEVICE_ATTR_RO(valid_zones); > #endif > >-static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); >-static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state); >-static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL); >-static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL); >+static DEVICE_ATTR_RO(phys_index); >+static DEVICE_ATTR_RW(state); >+static DEVICE_ATTR_RO(phys_device); >+static DEVICE_ATTR_RO(removable); > > /* > * Block size attribute stuff > */ >-static ssize_t >-print_block_size(struct device *dev, struct device_attribute *attr, >- char *buf) >+static ssize_t block_size_bytes_show(struct device *dev, >+ struct device_attribute *attr, char *buf) > { > return sprintf(buf, "%lx\n", get_memory_block_size()); > } > >-static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL); >+static DEVICE_ATTR_RO(block_size_bytes); > > /* > * Memory auto online policy. > */ > >-static ssize_t >-show_auto_online_blocks(struct device *dev, struct device_attribute *attr, >- char *buf) >+static ssize_t auto_online_blocks_show(struct device *dev, >+ struct device_attribute *attr, char *buf) > { > if (memhp_auto_online) > return sprintf(buf, "online\n"); >@@ -469,9 +466,9 @@ show_auto_online_blocks(struct device *dev, struct device_attribute *attr, > return sprintf(buf, "offline\n"); > } > >-static ssize_t >-store_auto_online_blocks(struct device *dev, struct device_attribute *attr, >- const char *buf, size_t count) >+static ssize_t auto_online_blocks_store(struct device *dev, >+ struct device_attribute *attr, >+ const char *buf, size_t count) > { > if (sysfs_streq(buf, "online")) > memhp_auto_online = true; >@@ -483,8 +480,7 @@ store_auto_online_blocks(struct device *dev, struct device_attribute *attr, > return count; > } > >-static DEVICE_ATTR(auto_online_blocks, 0644, show_auto_online_blocks, >- store_auto_online_blocks); >+static DEVICE_ATTR_RW(auto_online_blocks); > > /* > * Some architectures will have custom drivers to do this, and >@@ -493,9 +489,8 @@ static DEVICE_ATTR(auto_online_blocks, 0644, show_auto_online_blocks, > * and will require this interface. > */ > #ifdef CONFIG_ARCH_MEMORY_PROBE >-static ssize_t >-memory_probe_store(struct device *dev, struct device_attribute *attr, >- const char *buf, size_t count) >+static ssize_t probe_store(struct device *dev, struct device_attribute *attr, >+ const char *buf, size_t count) > { > u64 phys_addr; > int nid, ret; >@@ -525,7 +520,7 @@ memory_probe_store(struct device *dev, struct device_attribute *attr, > return ret; > } > >-static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store); >+static DEVICE_ATTR_WO(probe); > #endif > > #ifdef CONFIG_MEMORY_FAILURE >@@ -534,10 +529,9 @@ static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store); > */ > > /* Soft offline a page */ >-static ssize_t >-store_soft_offline_page(struct device *dev, >- struct device_attribute *attr, >- const char *buf, size_t count) >+static ssize_t soft_offline_page_store(struct device *dev, >+ struct device_attribute *attr, >+ const char *buf, size_t count) > { > int ret; > u64 pfn; >@@ -553,10 +547,9 @@ store_soft_offline_page(struct device *dev, > } > > /* Forcibly offline a page, including killing processes. */ >-static ssize_t >-store_hard_offline_page(struct device *dev, >- struct device_attribute *attr, >- const char *buf, size_t count) >+static ssize_t hard_offline_page_store(struct device *dev, >+ struct device_attribute *attr, >+ const char *buf, size_t count) > { > int ret; > u64 pfn; >@@ -569,8 +562,8 @@ store_hard_offline_page(struct device *dev, > return ret ? ret : count; > } > >-static DEVICE_ATTR(soft_offline_page, S_IWUSR, NULL, store_soft_offline_page); >-static DEVICE_ATTR(hard_offline_page, S_IWUSR, NULL, store_hard_offline_page); >+static DEVICE_ATTR_WO(soft_offline_page); >+static DEVICE_ATTR_WO(hard_offline_page); > #endif > > /* >-- >2.17.2 -- Wei Yang Help you, Help me