Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp88351iog; Wed, 29 Jun 2022 18:49:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vKfyUb04+Z1sXAwoNlAZPyp8phZrT+vfLdHHQSQKNwgejUuljMzHXJ6lto3ipsZtVAhav5 X-Received: by 2002:a17:90a:c6:b0:1ed:362d:a7dd with SMTP id v6-20020a17090a00c600b001ed362da7ddmr7131200pjd.228.1656553762587; Wed, 29 Jun 2022 18:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656553762; cv=none; d=google.com; s=arc-20160816; b=f4ZjxGszM6eynrC2Yk8qeO/A7sASfEIwur5vITRy8vFfGgzTcMq+RQtb+il0UI4SfY wMaH83Tze7KuP22IU5/v57W4joTraS61Pu8DbLM836e2ZeV4yYPN6LktxrquFEv74LYR edR8vDTdspEz8BwUxL1p+0PMl79cLlsV1XUWUaZimfmclIbIA1IBDASHGZdC2I7Zv+Jr V2IDqb81+zxBuF0tPE7LN+OPVikK4fIpUfH7HgbP3pDZpo8N/EkbsETMX1k/s5pDEvqY RsFjK7mTC25Qlbiikljk/PSPuRrgnT+suZaK2GM2tGjnIm3qQwrdQ4iEul32zRmIHReX 409g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=tSyIkl414kihd6yjmL3Tl7tUyNEI6/VwJHji+e04bU0=; b=CvM6N26pImmH+HCrHN1CLhFRTbsLj+OHAcj4YXhRtrYVtPOBHEY+vUxRJcHST/DjU5 8iv/14xYNvJeCPQ2pY7IkqjmzgrUHlcCZ2zjjU+Juhbf0QZn5axD6tpdrdsJPVof29Q2 VWQM+wsuIW/kj/YAMPdVkp4GB+cPRMQcQp6RgAV0tTuipXouNpdFLdlEGWUw/SNDWLSv caWGlDYC5CoPnDoEYxjci9OOiVef9fooduNPPYON+EEUQblgCjxX8cAwXNFmi76Lh0cK ttDZ4/kS1Dof249P/+92cS6/zguMfEZ5TiHVFy1kvT5I+Aiu3DpI7nFSRz1uBGPahioV Amyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d125-20020a636883000000b004119d1bc2b3si1612192pgc.431.2022.06.29.18.49.09; Wed, 29 Jun 2022 18:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbiF3Boh convert rfc822-to-8bit (ORCPT + 99 others); Wed, 29 Jun 2022 21:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbiF3Boc (ORCPT ); Wed, 29 Jun 2022 21:44:32 -0400 X-Greylist: delayed 4037 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 29 Jun 2022 18:44:30 PDT Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D11922252D; Wed, 29 Jun 2022 18:44:30 -0700 (PDT) Received: from omf12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D64CE21072; Thu, 30 Jun 2022 01:44:26 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA id 5CB071D; Thu, 30 Jun 2022 01:44:15 +0000 (UTC) Message-ID: <1a1f24707a03c2363e29ef91905e9f206fb6a0b5.camel@perches.com> Subject: Re: [PATCH] remove CONFIG_ANDROID From: Joe Perches To: "Jason A. Donenfeld" Cc: Kalesh Singh , Christoph Hellwig , Greg Kroah-Hartman , Arve =?ISO-8859-1?Q?Hj=F8nnev=E5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Theodore Ts'o , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Alex Xu (Hello71)" , Paolo Abeni , Rob Herring , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Shuah Khan , LKML , wireguard@lists.zx2c4.com, netdev@vger.kernel.org, rcu , "open list:KERNEL SELFTEST FRAMEWORK" , sultan@kerneltoast.com, android-kernel-team , John Stultz , Saravana Kannan , rafael@kernel.org Date: Wed, 29 Jun 2022 18:44:14 -0700 In-Reply-To: References: <20220629163007.GA25279@lst.de> <306dacfb29c2e38312943fa70d419f0a8d5ffe82.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Stat-Signature: zbdp5d9fuytdswy6hfx17qhqzd7ozzw8 X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: 5CB071D X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX19rCBqUb9HrdxbUJs3SdsgdKdwaYSpMY7s= X-HE-Tag: 1656553455-953600 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-06-30 at 02:50 +0200, Jason A. Donenfeld wrote: > On Wed, Jun 29, 2022 at 05:36:57PM -0700, Joe Perches wrote: > > > > +static ssize_t pm_userspace_autosleeper_show(struct kobject *kobj, > > > > + struct kobj_attribute *attr, char *buf) > > > > +{ > > > > + return sprintf(buf, "%d\n", pm_userspace_autosleeper_enabled); > > > > This should use sysfs_emit no? > > Probably, yea. Note that I just copy and pasted a nearby function, > pm_async_show, `:%s/`d the variable name, and then promptly `git diff | > clip`d it and plonked it into my email. Looking at the file, it uses > sprintf all over the place in this fashion. So you may want to submit a > cleanup to Rafael on this if you're right about sysfs_emit() being > universally preferred. Perhaps: (trivial refactored and added a missing newline in autosleep_show) --- kernel/power/main.c | 102 ++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/kernel/power/main.c b/kernel/power/main.c index e3694034b7536..c8a030319b15c 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -100,7 +100,7 @@ int pm_async_enabled = 1; static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", pm_async_enabled); + return sysfs_emit(buf, "%d\n", pm_async_enabled); } static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -124,27 +124,25 @@ power_attr(pm_async); static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - char *s = buf; + int len = 0; suspend_state_t i; for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) { if (i >= PM_SUSPEND_MEM && cxl_mem_active()) continue; - if (mem_sleep_states[i]) { - const char *label = mem_sleep_states[i]; + if (!mem_sleep_states[i]) + continue; - if (mem_sleep_current == i) - s += sprintf(s, "[%s] ", label); - else - s += sprintf(s, "%s ", label); - } + len += sysfs_emit_at(buf, len, + mem_sleep_current == i ? "[%s] " : "%s ", + mem_sleep_states[i]); } - /* Convert the last space to a newline if needed. */ - if (s != buf) - *(s-1) = '\n'; + /* Convert the last space to a newline if needed */ + if (len) + sysfs_emit_at(buf, len - 1, "\n"); - return (s - buf); + return len; } static suspend_state_t decode_suspend_state(const char *buf, size_t n) @@ -205,7 +203,7 @@ bool sync_on_suspend_enabled = !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC); static ssize_t sync_on_suspend_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", sync_on_suspend_enabled); + return sysfs_emit(buf, "%d\n", sync_on_suspend_enabled); } static ssize_t sync_on_suspend_store(struct kobject *kobj, @@ -242,22 +240,22 @@ static const char * const pm_tests[__TEST_AFTER_LAST] = { static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - char *s = buf; + int len = 0; int level; - for (level = TEST_FIRST; level <= TEST_MAX; level++) - if (pm_tests[level]) { - if (level == pm_test_level) - s += sprintf(s, "[%s] ", pm_tests[level]); - else - s += sprintf(s, "%s ", pm_tests[level]); - } + for (level = TEST_FIRST; level <= TEST_MAX; level++) { + if (!pm_tests[level]) + continue; + len += sysfs_emit_at(buf, len, + level == pm_test_level ? "[%s] " : "%s ", + pm_tests[level]); + } - if (s != buf) - /* convert the last space to a newline */ - *(s-1) = '\n'; + /* convert the last space to a newline if needed */ + if (len) + sysfs_emit_at(buf, len - 1, "\n"); - return (s - buf); + return len; } static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -314,7 +312,7 @@ static char *suspend_step_name(enum suspend_stat_step step) static ssize_t _name##_show(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ - return sprintf(buf, "%d\n", suspend_stats._name); \ + return sysfs_emit(buf, "%d\n", suspend_stats._name); \ } \ static struct kobj_attribute _name = __ATTR_RO(_name) @@ -339,7 +337,7 @@ static ssize_t last_failed_dev_show(struct kobject *kobj, index %= REC_FAILED_NUM; last_failed_dev = suspend_stats.failed_devs[index]; - return sprintf(buf, "%s\n", last_failed_dev); + return sysfs_emit(buf, "%s\n", last_failed_dev); } static struct kobj_attribute last_failed_dev = __ATTR_RO(last_failed_dev); @@ -353,7 +351,7 @@ static ssize_t last_failed_errno_show(struct kobject *kobj, index %= REC_FAILED_NUM; last_failed_errno = suspend_stats.errno[index]; - return sprintf(buf, "%d\n", last_failed_errno); + return sysfs_emit(buf, "%d\n", last_failed_errno); } static struct kobj_attribute last_failed_errno = __ATTR_RO(last_failed_errno); @@ -369,7 +367,7 @@ static ssize_t last_failed_step_show(struct kobject *kobj, step = suspend_stats.failed_steps[index]; last_failed_step = suspend_step_name(step); - return sprintf(buf, "%s\n", last_failed_step); + return sysfs_emit(buf, "%s\n", last_failed_step); } static struct kobj_attribute last_failed_step = __ATTR_RO(last_failed_step); @@ -477,7 +475,7 @@ bool pm_print_times_enabled; static ssize_t pm_print_times_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", pm_print_times_enabled); + return sysfs_emit(buf, "%d\n", pm_print_times_enabled); } static ssize_t pm_print_times_store(struct kobject *kobj, @@ -510,7 +508,7 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj, if (!pm_wakeup_irq()) return -ENODATA; - return sprintf(buf, "%u\n", pm_wakeup_irq()); + return sysfs_emit(buf, "%u\n", pm_wakeup_irq()); } power_attr_ro(pm_wakeup_irq); @@ -520,7 +518,7 @@ bool pm_debug_messages_on __read_mostly; static ssize_t pm_debug_messages_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", pm_debug_messages_on); + return sysfs_emit(buf, "%d\n", pm_debug_messages_on); } static ssize_t pm_debug_messages_store(struct kobject *kobj, @@ -568,21 +566,24 @@ struct kobject *power_kobj; static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - char *s = buf; + int len = 0; #ifdef CONFIG_SUSPEND suspend_state_t i; - for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) + for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) { if (pm_states[i]) - s += sprintf(s,"%s ", pm_states[i]); + len += sysfs_emit_at(buf, len, "%s ", pm_states[i]); + } #endif if (hibernation_available()) - s += sprintf(s, "disk "); - if (s != buf) - /* convert the last space to a newline */ - *(s-1) = '\n'; - return (s - buf); + len += sysfs_emit_at(buf, len, "disk "); + + /* convert the last space to a newline if needed */ + if (len) + sysfs_emit_at(buf, len - 1, "\n"); + + return len; } static suspend_state_t decode_state(const char *buf, size_t n) @@ -681,8 +682,10 @@ static ssize_t wakeup_count_show(struct kobject *kobj, { unsigned int val; - return pm_get_wakeup_count(&val, true) ? - sprintf(buf, "%u\n", val) : -EINTR; + if (!pm_get_wakeup_count(&val, true)) + return -EINTR; + + return sysfs_emit(buf, "%u\n", val); } static ssize_t wakeup_count_store(struct kobject *kobj, @@ -724,17 +727,16 @@ static ssize_t autosleep_show(struct kobject *kobj, suspend_state_t state = pm_autosleep_state(); if (state == PM_SUSPEND_ON) - return sprintf(buf, "off\n"); + return sysfs_emit(buf, "off\n"); #ifdef CONFIG_SUSPEND if (state < PM_SUSPEND_MAX) - return sprintf(buf, "%s\n", pm_states[state] ? - pm_states[state] : "error"); + return sysfs_emit(buf, "%s\n", pm_states[state] ?: "error"); #endif #ifdef CONFIG_HIBERNATION - return sprintf(buf, "disk\n"); + return sysfs_emit(buf, "disk\n"); #else - return sprintf(buf, "error"); + return sysfs_emit(buf, "error\n"); #endif } @@ -803,7 +805,7 @@ int pm_trace_enabled; static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%d\n", pm_trace_enabled); + return sysfs_emit(buf, "%d\n", pm_trace_enabled); } static ssize_t @@ -840,7 +842,7 @@ power_attr_ro(pm_trace_dev_match); static ssize_t pm_freeze_timeout_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "%u\n", freeze_timeout_msecs); + return sysfs_emit(buf, "%u\n", freeze_timeout_msecs); } static ssize_t pm_freeze_timeout_store(struct kobject *kobj,