From patchwork Thu Jan 13 18:44:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 531913 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 D7FE2C433EF for ; Thu, 13 Jan 2022 18:44:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237606AbiAMSoa (ORCPT ); Thu, 13 Jan 2022 13:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237605AbiAMSoa (ORCPT ); Thu, 13 Jan 2022 13:44:30 -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 83026C061574; Thu, 13 Jan 2022 10:44:29 -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 B8DB4B8232C; Thu, 13 Jan 2022 18:44:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0274AC36AEB; Thu, 13 Jan 2022 18:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1642099466; bh=Ri69dcy2uJ+yyDCUJgdfeWRcfe9AD7l5RsFcm1ESMJk=; h=From:To:Cc:Subject:Date:From; b=aUlCuDIBXxruaFqRNCgtwcoIxgGBO6unI/WoBI32mEfqS5DE6G1uGorQCKYhlwd7P s85mIRF1UUkol+WxK9Le/AXlbn/lD8GBbO+4h2Rd2KDO3MOhAJud+Y60QaFa7NQ2Cg ALv1SpczGbk4CDJmUetBsAEtSqGRSilSB4YsaSs0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Pavel Machek , Len Brown , linux-pm@vger.kernel.org, Lee Jones Subject: [PATCH] pm / wakeup: simplify the output logic of pm_show_wakelocks() Date: Thu, 13 Jan 2022 19:44:20 +0100 Message-Id: <20220113184420.2504545-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1545; h=from:subject; bh=Ri69dcy2uJ+yyDCUJgdfeWRcfe9AD7l5RsFcm1ESMJk=; b=owGbwMvMwCRo6H6F97bub03G02pJDIkPipkeX054/+ph+nu77liLaTe/Tb+4pnJiqnnj7WuP3kyU /jLBryOWhUGQiUFWTJHlyzaeo/srDil6GdqehpnDygQyhIGLUwAmcnwHw4LJPVfMn+ideMi45u7nuS 8TAh5OP6jKsGDq8ZM35Odv+ibkICQevDVuAT8nQx4A X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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. Cc: "Rafael J. Wysocki" Cc: Pavel Machek Cc: Len Brown Cc: linux-pm@vger.kernel.org Cc: Lee Jones Signed-off-by: Greg Kroah-Hartman --- 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 105df4dfc783..52571dcad768 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