From patchwork Tue May 11 06:18:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 12250751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80900C433ED for ; Tue, 11 May 2021 11:39:24 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C727561028 for ; Tue, 11 May 2021 11:39:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C727561028 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Cm6E0z79vINnJJei03VVgjPRrZJcgNtiwlUDJyMYQcA=; b=jJ3w9fR2MXJrEfl+iPthAgPXz1 EDQtK9peMLh4/1HZe7BawqcVAOeIBGWjyZi9kKPOauB+MjYG4Qbi0ibPztp83jzeOUXl4HznYhRTd VlUk4FL/BRr0RQwDpKZQyr0D/C4hvtL+k6JU1kgcPkjQOzkA8M1ZYzcwIx0R2L8/4R1XqUXRSMm5c SlVaMkHQWr8EcMdqQHxL7z00m88QrpK+IR2bGIOO+5t7UCg9g8HOqoUC3wfSGXSX+YNzdj89aIuTI rmaQfIGIC7mbKz9FdL1k0SPIFK2FEtxYIt/7PVQkiJ43gU+s3dTTFAlb78R7Lhxqq+AbOmOS9nAvb KJkdjuSA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgQiD-00HADD-Df; Tue, 11 May 2021 11:38:05 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgLiw-00GOdM-Ct for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 06:18:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=bbXPgmZrL4Pxh0/t8XE8baUOCONdkg5IyBFSdmqHWjM=; b=1MaD0jBT5t1v1LKD46vz56MzEa vJec6bTXDHqkGhoa1Rd1hyM5mLivsZeDyEAQ2KcoM/TET13pcJHL2mtiVpoF2wEpXok2scsLmuETV TeEV0DnMo1nXUON0olUMq4Mzd2ZFIW3cbm/YcWaJ4mEH1A3NZy8NRTMP3o4eerVk0r+SzDIvlyR4r brpfrxL40VfD9+RzHxwXmnvYntAg0rU0/6HV6ZsAz8gF65nYhuoKDvB067A58D4ZMpG49AE8FVlnK rZUTXUnOBa0wb/V9PRAt5Q4yBwYV97tpreTvX1D02HQCJZfe6lMfh8vKG1GHCRCRoy6AC6htH4IvW cwY+rQeQ==; Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgLis-009Khv-Hi for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 06:18:28 +0000 Received: from mail-ej1-f69.google.com ([209.85.218.69]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lgLio-0001yG-6P for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 06:18:22 +0000 Received: by mail-ej1-f69.google.com with SMTP id qk30-20020a170906d9deb02903916754e1b6so5541302ejb.2 for ; Mon, 10 May 2021 23:18:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bbXPgmZrL4Pxh0/t8XE8baUOCONdkg5IyBFSdmqHWjM=; b=gLOU0kpm16UNPalxyPmp3MeOjTr+lhvqh8savBfhu+TPLW+3yKGushVSgYfRasfMJj lMoJng3l8JWNxrjMcxkwe7tvWfn+6USJUL9tGUSSwZS2iWC/pR8vsZ8G9XRLoNt4AdWV QbCEOrWkt6y6TjTM1RP0eZl8HEX8x9bGpcbcWOtVvPIDtLJtPgKp7TUxQQKBTRF8LFzy E737Seoea35fJkCqtUv7Z2UxV30hKP3rlZkSI/QlSsZyVcgDDHZnZ5D6FPNggsj9Z2i8 pOfAybNMSCdR4r/KNp9zv9tGpY43vtluCEWz50YtXrAHlZGBiPMmAra2KarfV+99B7uG oKvQ== X-Gm-Message-State: AOAM5332f5liaWFQAqTOpyX7XDt7hxytBeSUTrw3VGLW0NRHE0qg5DRg ZxuviA40Fg4Xjjfl64MYNYhV9GlO0OfiyK9MesvjjeuuUH1Rh67JPUZLKO6hEMCnHR5S4wJBR3w NnDPT7WoLlAw3OKeVY1xRDMSGy1zWTSJgR5cMzzRMaON2CWH6kVLP X-Received: by 2002:a17:906:9246:: with SMTP id c6mr30337745ejx.10.1620713901801; Mon, 10 May 2021 23:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuFUKxnlEC58W09fcC4t8RpefrIfBsHhh1rU2Dzq5wghcRbv5j9OslBqjPeLytqr3YNEzFFg== X-Received: by 2002:a17:906:9246:: with SMTP id c6mr30337730ejx.10.1620713901627; Mon, 10 May 2021 23:18:21 -0700 (PDT) Received: from gollum.fritz.box ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id gn36sm10616136ejc.23.2021.05.10.23.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 23:18:21 -0700 (PDT) From: Juerg Haefliger X-Google-Original-From: Juerg Haefliger To: wim@linux-watchdog.org, linux@roeck-us.net, joel@jms.id.au, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org Cc: andrew@aj.id.au, linux-kernel@vger.kernel.org, Juerg Haefliger Subject: [PATCH] watchdog: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 11 May 2021 08:18:12 +0200 Message-Id: <20210511061812.480172-1-juergh@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_231826_746734_DA6088D5 X-CRM114-Status: GOOD ( 11.30 ) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_231826_746734_DA6088D5 X-CRM114-Status: UNSURE ( 5.86 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Convert sprintf() in sysfs "show" functions to sysfs_emit() and sysfs_emit_at() in order to check for buffer overruns in sysfs outputs. Signed-off-by: Juerg Haefliger Reviewed-by: Guenter Roeck --- drivers/watchdog/aspeed_wdt.c | 4 ++-- drivers/watchdog/watchdog_dev.c | 19 ++++++++++--------- drivers/watchdog/watchdog_pretimeout.c | 4 ++-- drivers/watchdog/ziirave_wdt.c | 12 +++++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index 7e00960651fa..933998e5a9de 100644 --- a/drivers/watchdog/aspeed_wdt.c +++ b/drivers/watchdog/aspeed_wdt.c @@ -175,8 +175,8 @@ static ssize_t access_cs0_show(struct device *dev, struct aspeed_wdt *wdt = dev_get_drvdata(dev); u32 status = readl(wdt->base + WDT_TIMEOUT_STATUS); - return sprintf(buf, "%u\n", - !(status & WDT_TIMEOUT_STATUS_BOOT_SECONDARY)); + return sysfs_emit(buf, "%u\n", + !(status & WDT_TIMEOUT_STATUS_BOOT_SECONDARY)); } static ssize_t access_cs0_store(struct device *dev, diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 2946f3a63110..fe68a97973a5 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -451,7 +451,8 @@ static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr, { struct watchdog_device *wdd = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status)); + return sysfs_emit(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, + &wdd->status)); } static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr, @@ -485,7 +486,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, status = watchdog_get_status(wdd); mutex_unlock(&wd_data->lock); - return sprintf(buf, "0x%x\n", status); + return sysfs_emit(buf, "0x%x\n", status); } static DEVICE_ATTR_RO(status); @@ -494,7 +495,7 @@ static ssize_t bootstatus_show(struct device *dev, { struct watchdog_device *wdd = dev_get_drvdata(dev); - return sprintf(buf, "%u\n", wdd->bootstatus); + return sysfs_emit(buf, "%u\n", wdd->bootstatus); } static DEVICE_ATTR_RO(bootstatus); @@ -510,7 +511,7 @@ static ssize_t timeleft_show(struct device *dev, struct device_attribute *attr, status = watchdog_get_timeleft(wdd, &val); mutex_unlock(&wd_data->lock); if (!status) - status = sprintf(buf, "%u\n", val); + status = sysfs_emit(buf, "%u\n", val); return status; } @@ -521,7 +522,7 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr, { struct watchdog_device *wdd = dev_get_drvdata(dev); - return sprintf(buf, "%u\n", wdd->timeout); + return sysfs_emit(buf, "%u\n", wdd->timeout); } static DEVICE_ATTR_RO(timeout); @@ -530,7 +531,7 @@ static ssize_t pretimeout_show(struct device *dev, { struct watchdog_device *wdd = dev_get_drvdata(dev); - return sprintf(buf, "%u\n", wdd->pretimeout); + return sysfs_emit(buf, "%u\n", wdd->pretimeout); } static DEVICE_ATTR_RO(pretimeout); @@ -539,7 +540,7 @@ static ssize_t identity_show(struct device *dev, struct device_attribute *attr, { struct watchdog_device *wdd = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", wdd->info->identity); + return sysfs_emit(buf, "%s\n", wdd->info->identity); } static DEVICE_ATTR_RO(identity); @@ -549,9 +550,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, struct watchdog_device *wdd = dev_get_drvdata(dev); if (watchdog_active(wdd)) - return sprintf(buf, "active\n"); + return sysfs_emit(buf, "active\n"); - return sprintf(buf, "inactive\n"); + return sysfs_emit(buf, "inactive\n"); } static DEVICE_ATTR_RO(state); diff --git a/drivers/watchdog/watchdog_pretimeout.c b/drivers/watchdog/watchdog_pretimeout.c index 01ca84be240f..7f257c3485cd 100644 --- a/drivers/watchdog/watchdog_pretimeout.c +++ b/drivers/watchdog/watchdog_pretimeout.c @@ -55,7 +55,7 @@ int watchdog_pretimeout_available_governors_get(char *buf) mutex_lock(&governor_lock); list_for_each_entry(priv, &governor_list, entry) - count += sprintf(buf + count, "%s\n", priv->gov->name); + count += sysfs_emit_at(buf, count, "%s\n", priv->gov->name); mutex_unlock(&governor_lock); @@ -68,7 +68,7 @@ int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf) spin_lock_irq(&pretimeout_lock); if (wdd->gov) - count = sprintf(buf, "%s\n", wdd->gov->name); + count = sysfs_emit(buf, "%s\n", wdd->gov->name); spin_unlock_irq(&pretimeout_lock); return count; diff --git a/drivers/watchdog/ziirave_wdt.c b/drivers/watchdog/ziirave_wdt.c index 4297280807ca..6c9414d09684 100644 --- a/drivers/watchdog/ziirave_wdt.c +++ b/drivers/watchdog/ziirave_wdt.c @@ -445,8 +445,9 @@ static ssize_t ziirave_wdt_sysfs_show_firm(struct device *dev, if (ret) return ret; - ret = sprintf(buf, ZIIRAVE_FW_VERSION_FMT, w_priv->firmware_rev.major, - w_priv->firmware_rev.minor); + ret = sysfs_emit(buf, ZIIRAVE_FW_VERSION_FMT, + w_priv->firmware_rev.major, + w_priv->firmware_rev.minor); mutex_unlock(&w_priv->sysfs_mutex); @@ -468,8 +469,9 @@ static ssize_t ziirave_wdt_sysfs_show_boot(struct device *dev, if (ret) return ret; - ret = sprintf(buf, ZIIRAVE_BL_VERSION_FMT, w_priv->bootloader_rev.major, - w_priv->bootloader_rev.minor); + ret = sysfs_emit(buf, ZIIRAVE_BL_VERSION_FMT, + w_priv->bootloader_rev.major, + w_priv->bootloader_rev.minor); mutex_unlock(&w_priv->sysfs_mutex); @@ -491,7 +493,7 @@ static ssize_t ziirave_wdt_sysfs_show_reason(struct device *dev, if (ret) return ret; - ret = sprintf(buf, "%s", ziirave_reasons[w_priv->reset_reason]); + ret = sysfs_emit(buf, "%s", ziirave_reasons[w_priv->reset_reason]); mutex_unlock(&w_priv->sysfs_mutex);