From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAD20C433F5 for ; Thu, 3 Feb 2022 20:37:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355159AbiBCUhH (ORCPT ); Thu, 3 Feb 2022 15:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355111AbiBCUe7 (ORCPT ); Thu, 3 Feb 2022 15:34:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27164C0613DC; Thu, 3 Feb 2022 12:34:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BFC24B835B5; Thu, 3 Feb 2022 20:34:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 702B5C340F6; Thu, 3 Feb 2022 20:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643920440; bh=e7++UKLnpHgdLY0wud0yHtptEMp6tU2m8lqkAWd9MCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nb1bMryvwpf9mdeD1FCQQfI4qUH/KrwYzH+UqETkieCtm+M03PEDYBVYOMHP/1lAx RkhkLBqSDHeRmAMc+4PEhjPt2+SMFDfK41hK2hbNGZpVQlK+j53HoEchL7JzVS5kkb HnFPcKNhZOTvLEsp8v2Q6r9iYCnCb56vjH4g+p+apLPpDJnUNo1NEa83ztpGRBG79l f2O6KvU7nj4GBUDKrEiHX1VoMDR1zlfP2SlO4RLZzpkPk0Z+vPD0GLwhkLbwJeldPJ ViKYMaWqc+00CW/OVAtsSsZIBU9wGHf1bCtm0MnNtVHpip6bkep6zWHN4HD0Xi0NY0 R+m2KtMPWYe9g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Lee Jones , "Rafael J . Wysocki" , Sasha Levin , rafael@kernel.org, pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 33/41] PM: wakeup: simplify the output logic of pm_show_wakelocks() Date: Thu, 3 Feb 2022 15:32:37 -0500 Message-Id: <20220203203245.3007-33-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203203245.3007-1-sashal@kernel.org> References: <20220203203245.3007-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman [ Upstream commit c9d967b2ce40d71e968eb839f36c936b8a9cf1ea ] The buffer handling in pm_show_wakelocks() is tricky, and hopefully correct. Ensure it really is correct by using sysfs_emit_at() which handles all of the tricky string handling logic in a PAGE_SIZE buffer for us automatically as this is a sysfs file being read from. Signed-off-by: Greg Kroah-Hartman Reviewed-by: Lee Jones Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- kernel/power/wakelock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c index 105df4dfc7839..52571dcad768b 100644 --- a/kernel/power/wakelock.c +++ b/kernel/power/wakelock.c @@ -39,23 +39,20 @@ ssize_t pm_show_wakelocks(char *buf, bool show_active) { struct rb_node *node; struct wakelock *wl; - char *str = buf; - char *end = buf + PAGE_SIZE; + int len = 0; mutex_lock(&wakelocks_lock); for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) { wl = rb_entry(node, struct wakelock, node); if (wl->ws->active == show_active) - str += scnprintf(str, end - str, "%s ", wl->name); + len += sysfs_emit_at(buf, len, "%s ", wl->name); } - if (str > buf) - str--; - str += scnprintf(str, end - str, "\n"); + len += sysfs_emit_at(buf, len, "\n"); mutex_unlock(&wakelocks_lock); - return (str - buf); + return len; } #if CONFIG_PM_WAKELOCKS_LIMIT > 0 -- 2.34.1