Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1774789pxb; Wed, 9 Feb 2022 04:20:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTVZi+x4SIRvnS1Qiy0I3Ykm6UFj0bGmtteetq32Ne1wqROZwyXjA2YZ1JaMp3yVaxR9LA X-Received: by 2002:a65:6681:: with SMTP id b1mr1661007pgw.221.1644409202326; Wed, 09 Feb 2022 04:20:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644409202; cv=none; d=google.com; s=arc-20160816; b=oibIUqqCg/hEGXyH6p2MPm78rK2tfJCJhbGseaKcSd2jfERjt8fTDSsV3vQF007pdv IYR/ZOTGxW0+XohuqhC0NsJAaPMoU2c5thTnbGh7gCK0Abp1p4Qd/1wweame3BogCrJe ufGvTpWZETA+KqJGs9+bo6u4tSlcRLvgDbpr9xE/HhA6h7/drAmBy9+qVzDMrW17fM6u u60Z6A+BiiyKiOwey3sJUOK3IGTuWibqaJdrepPPWHiJX75Ciw4xVHrZMJgBUEIi5u5M tQGnR0EXkGWtEuQnYuOLM2tTKMTKW9J3NelEZRq4TkOHcvHBhSAUu5VZUacj24x0RMCe Zw0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4QnjAQE3/UVjlFQGslN6mJ6geoXfmMW+PEZjnNuBzao=; b=bBUN7k3ZHK7mkjjJSMYS2gR6paVz6U1IcmIbBsfUagOjVzZfbIo7I7ORqNpSHl+qKF ko9X/nSTFcxyV9qLUz4FQo7dxKEedroh/1Xd94AFrBCtvD4kz3HfAS5qoZqgRbu2sFZ6 OnR024uoeYE7XAkuxWQMIlMj983Zftnl1+3zOF9+FM0L264JR41uPmHGq2j+6/dVF7np QC3jqpkY5XF1S73DMv7upKzVnDzh9ZoiCt2JRQ4UENa3op9abN68dwZqYLeHwEQoKTB7 hnzC/6mHtIoJl8uObUL5LWEMRmW9XJSfS81kGW8fZklmPaLtTT6P2UMmYtOl0vx7nFsq 97jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uTYhamhX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 30si9901415pgw.552.2022.02.09.04.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:20:02 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uTYhamhX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84DD5E08B99E; Wed, 9 Feb 2022 02:14:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382585AbiBGLTv (ORCPT + 99 others); Mon, 7 Feb 2022 06:19:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376484AbiBGLPK (ORCPT ); Mon, 7 Feb 2022 06:15:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B0CC03FEDB; Mon, 7 Feb 2022 03:14:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2090D6140B; Mon, 7 Feb 2022 11:14:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08331C004E1; Mon, 7 Feb 2022 11:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232488; bh=fWA7+yWKegMS40cpvXEP1/eohdqQT4jfg/9bqF05LxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTYhamhXzYsReJHw0oq+jxd1TMpCibGFRhDRtsrmv4hkFkSZvPYQWCpbyxpvi1oi5 3wJ1h+f1BrvaHAmxVF8nRXFe89Cb6vJc/uxpHyWsPd1oFsiHjbZV7PJigr9lc5uJOs VAGOPT7CtzrNxXG44SxfbQLpXj2fLkwN+3BELkLM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lee Jones , "Rafael J. Wysocki" Subject: [PATCH 4.19 06/86] PM: wakeup: simplify the output logic of pm_show_wakelocks() Date: Mon, 7 Feb 2022 12:05:29 +0100 Message-Id: <20220207103757.765932137@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 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 From: Greg Kroah-Hartman commit c9d967b2ce40d71e968eb839f36c936b8a9cf1ea upstream. 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. Reviewed-by: Lee Jones Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- kernel/power/wakelock.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/kernel/power/wakelock.c +++ b/kernel/power/wakelock.c @@ -39,23 +39,19 @@ ssize_t pm_show_wakelocks(char *buf, boo { 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