From patchwork Sat May 15 05:24:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259437 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 E11ACC433ED for ; Sat, 15 May 2021 05:24:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A675C613CE for ; Sat, 15 May 2021 05:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbhEOFZv (ORCPT ); Sat, 15 May 2021 01:25:51 -0400 Received: from mail-ej1-f45.google.com ([209.85.218.45]:43759 "EHLO mail-ej1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbhEOFZu (ORCPT ); Sat, 15 May 2021 01:25:50 -0400 Received: by mail-ej1-f45.google.com with SMTP id l4so1553733ejc.10 for ; Fri, 14 May 2021 22:24:37 -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=f/Vo3vzWm4D00TYgfRuuEzVZKXz3CRt/yuqfwwH8YIU=; b=Yy7KfhuZbBHQULcj9oe3N/un0FFiS0hLa0XYNhjbbAoexUPwqogCXKjJPb/bZsq80E fqUsREn0X7VJLhyQ/BNdDL/kSiggrUPENH2wG7XpgrDs/MjcUu8U9Re0eBsoMHwHB1a2 /gxeHDPMC/VhmqedIVdFAMzWOZ5tzpdDIeG1yqSCIfpkK3MCgmexPMscbVc3zHrAG2XC 5dY/aFqFVKLMQ+zgcAcy/vVehQpZE5v6c89DmhGDtw2xr7bG8cedQN3JModG2NlXRmz9 R5G+W1yIata97q7U0cKQgfC0R55xFCcj35S76kgSJQrWY3lT7HYidSpGlDw0ajATu4Ne 3J4g== X-Gm-Message-State: AOAM533AUFgijxoszQ1W6f95h93KiKmPSEINGoTwjUtUMCVedUd4RTSU o+y+uSY0+5WtOfNVAQzhPLg= X-Google-Smtp-Source: ABdhPJwvfP1drkhLOi+o1WZL+eJ9323MVgRNp8o3OCPnzYBWrwDvAHI0LcagZhbnOoFcGoXpLrERxQ== X-Received: by 2002:a17:906:b0d:: with SMTP id u13mr8097847ejg.159.1621056276491; Fri, 14 May 2021 22:24:36 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:35 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:21 +0000 Message-Id: <20210515052434.1413236-1-kw@linux.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński Reviewed-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe --- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b717680377a9..5ed316ea5831 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6439,7 +6439,7 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) spin_lock(&resource_alignment_lock); if (resource_alignment_param) - count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param); + count = sysfs_emit(buf, "%s", resource_alignment_param); spin_unlock(&resource_alignment_lock); /* From patchwork Sat May 15 05:24:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259441 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 CA38CC433B4 for ; Sat, 15 May 2021 05:24:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9675613CE for ; Sat, 15 May 2021 05:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231320AbhEOFZw (ORCPT ); Sat, 15 May 2021 01:25:52 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:38675 "EHLO mail-ed1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbhEOFZv (ORCPT ); Sat, 15 May 2021 01:25:51 -0400 Received: by mail-ed1-f50.google.com with SMTP id n25so858687edr.5 for ; Fri, 14 May 2021 22:24:38 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=3ZSUDlxK2gpwJ+aSZRfjJrhrQ1Sy5cBzVVlZ7n5R5NA=; b=DY2ZIcubHKrhN2JJyGBg3SMrrzNHKxjokBnrw8i8rb/fHmSmWUFFaS+dXowN1993qj xyDc3ECBABEWTr8rm662bC37NCc3d2s1IFd55ZJl2N2Gpsu3wzIKE7Vt8NhrqQxHRwsg B7oJcbLUM5FD7QmBADqWR4RhwVYvbbaRZNaJ/nNlruUDQurmP7UKRvjP1/CDT1nebdal t+a63f/QmxGx5c/GyshCYtRTrbuUbMf9sj6zC5nI/6BU2gjrOzRkNx+oXdve8kbQvh6T QHckVKOINDCbOk+lQYFaB8KAMVb+Z8lvgsx5Rhn6QPpkzTpwR33qGP5zQiZHEgJq98+y p8rg== X-Gm-Message-State: AOAM532JgcwOYibOfV9y+IcGcLdNJlPAPmWAPlr2Lwm2F94tKVSaHeTj lJhQa4ojpRj6svF0/nwYEjQ= X-Google-Smtp-Source: ABdhPJyJzte6sbq66cNBekFBaDvvmVsrMqZqq1jO2TycXOtmpJpIHsRHKWSWGExUVijx0zjm8m/GsA== X-Received: by 2002:a05:6402:2750:: with SMTP id z16mr61413471edd.355.1621056277499; Fri, 14 May 2021 22:24:37 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:37 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 02/14] PCI/AER: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:22 +0000 Message-Id: <20210515052434.1413236-2-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pcie/aer.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index ec943cee5ecc..40ef7bed7a77 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -529,21 +529,23 @@ static const char *aer_agent_string[] = { char *buf) \ { \ unsigned int i; \ - char *str = buf; \ struct pci_dev *pdev = to_pci_dev(dev); \ u64 *stats = pdev->aer_stats->stats_array; \ + size_t len = 0; \ \ for (i = 0; i < ARRAY_SIZE(strings_array); i++) { \ if (strings_array[i]) \ - str += sprintf(str, "%s %llu\n", \ - strings_array[i], stats[i]); \ + len += sysfs_emit_at(buf, len, "%s %llu\n", \ + strings_array[i], \ + stats[i]); \ else if (stats[i]) \ - str += sprintf(str, #stats_array "_bit[%d] %llu\n",\ - i, stats[i]); \ + len += sysfs_emit_at(buf, len, \ + #stats_array "_bit[%d] %llu\n",\ + i, stats[i]); \ } \ - str += sprintf(str, "TOTAL_%s %llu\n", total_string, \ - pdev->aer_stats->total_field); \ - return str-buf; \ + len += sysfs_emit_at(buf, len, "TOTAL_%s %llu\n", total_string, \ + pdev->aer_stats->total_field); \ + return len; \ } \ static DEVICE_ATTR_RO(name) @@ -563,7 +565,7 @@ aer_stats_dev_attr(aer_dev_nonfatal, dev_nonfatal_errs, char *buf) \ { \ struct pci_dev *pdev = to_pci_dev(dev); \ - return sprintf(buf, "%llu\n", pdev->aer_stats->field); \ + return sysfs_emit(buf, "%llu\n", pdev->aer_stats->field); \ } \ static DEVICE_ATTR_RO(name) From patchwork Sat May 15 05:24:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259439 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 DF8E3C43461 for ; Sat, 15 May 2021 05:24:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93A7613F7 for ; Sat, 15 May 2021 05:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbhEOFZx (ORCPT ); Sat, 15 May 2021 01:25:53 -0400 Received: from mail-ej1-f48.google.com ([209.85.218.48]:46015 "EHLO mail-ej1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbhEOFZw (ORCPT ); Sat, 15 May 2021 01:25:52 -0400 Received: by mail-ej1-f48.google.com with SMTP id s22so1374869ejv.12 for ; Fri, 14 May 2021 22:24:39 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=VehsfxGHIqUkGXhHVF4getgAan5RIFGHUznH7GSNZdM=; b=GkbnBYJkHGawCLhzXEQbvHWwtV3OMhi+nUn7XWL7Af+jhJGWFRa3oI9Eqmaj8hphFx r4DDVZDNsSvSxxSIxrBxkVAlaKqDsOjZd0gplwFp1X+XukbPMimfOgZwf8f5OoxW5KwQ E2wxZ6+xPbMBgSL7DkpYbXR20+PDJM3wZr9b2lVzdqoZgHZG7lrl54gbw11GkunH41ub Gn515FowW3xwznYLR/MURAr0ev2FB42oTlKpVemVJ/QaUTQWGv5NRCewls/5e3V3UW3W ZWwgdge2vp4DeW3aoX/2FmmnKrHeynbfgcK66lF/4VO2kw34/IJWb5mvq3bYI+FWHAg6 85iA== X-Gm-Message-State: AOAM531y//6yO6z03cavUcvxTknHi6fUfn+p417NisF1iMczt4lsYS8E PX3TuI9lcFAx0DKeJTopU/g= X-Google-Smtp-Source: ABdhPJwCurKgC4IBTGpqO+Gv2xy5ReWjXsrDNYecNqjtR6Zj3eLiKAoAhFpYC0Pf+g0hsN/rgQPdOg== X-Received: by 2002:a17:906:d145:: with SMTP id br5mr50562471ejb.452.1621056278643; Fri, 14 May 2021 22:24:38 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:38 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 03/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:23 +0000 Message-Id: <20210515052434.1413236-3-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. Modify the function dsm_label_utf16s_to_utf8s() to directly return the number of bytes written into the buffer so that the strlen() used later to calculate the length of the buffer can be removed as it would no longer be needed. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-label.c | 18 ++++++++++-------- drivers/pci/slot.c | 16 ++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c index c32f3b7540e8..000e169c7197 100644 --- a/drivers/pci/pci-label.c +++ b/drivers/pci/pci-label.c @@ -139,14 +139,17 @@ enum acpi_attr_enum { ACPI_ATTR_INDEX_SHOW, }; -static void dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf) +static int dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf) { int len; + len = utf16s_to_utf8s((const wchar_t *)obj->buffer.pointer, obj->buffer.length, UTF16_LITTLE_ENDIAN, buf, PAGE_SIZE); buf[len] = '\n'; + + return len; } static int dsm_get_label(struct device *dev, char *buf, @@ -154,7 +157,7 @@ static int dsm_get_label(struct device *dev, char *buf, { acpi_handle handle = ACPI_HANDLE(dev); union acpi_object *obj, *tmp; - int len = -1; + int len = 0; if (!handle) return -1; @@ -175,20 +178,19 @@ static int dsm_get_label(struct device *dev, char *buf, * this entry must return a null string. */ if (attr == ACPI_ATTR_INDEX_SHOW) { - scnprintf(buf, PAGE_SIZE, "%llu\n", tmp->integer.value); + len = sysfs_emit(buf, "%llu\n", tmp->integer.value); } else if (attr == ACPI_ATTR_LABEL_SHOW) { if (tmp[1].type == ACPI_TYPE_STRING) - scnprintf(buf, PAGE_SIZE, "%s\n", - tmp[1].string.pointer); + len = sysfs_emit(buf, "%s\n", + tmp[1].string.pointer); else if (tmp[1].type == ACPI_TYPE_BUFFER) - dsm_label_utf16s_to_utf8s(tmp + 1, buf); + len = dsm_label_utf16s_to_utf8s(tmp + 1, buf); } - len = strlen(buf) > 0 ? strlen(buf) : -1; } ACPI_FREE(obj); - return len; + return len > 0 ? len : -1; } static ssize_t label_show(struct device *dev, struct device_attribute *attr, diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c index d627dd9179b4..7487e8f8f13f 100644 --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -39,19 +39,19 @@ static const struct sysfs_ops pci_slot_sysfs_ops = { static ssize_t address_read_file(struct pci_slot *slot, char *buf) { if (slot->number == 0xff) - return sprintf(buf, "%04x:%02x\n", - pci_domain_nr(slot->bus), - slot->bus->number); + return sysfs_emit(buf, "%04x:%02x\n", + pci_domain_nr(slot->bus), + slot->bus->number); else - return sprintf(buf, "%04x:%02x:%02x\n", - pci_domain_nr(slot->bus), - slot->bus->number, - slot->number); + return sysfs_emit(buf, "%04x:%02x:%02x\n", + pci_domain_nr(slot->bus), + slot->bus->number, + slot->number); } static ssize_t bus_speed_read(enum pci_bus_speed speed, char *buf) { - return sprintf(buf, "%s\n", pci_speed_string(speed)); + return sysfs_emit(buf, "%s\n", pci_speed_string(speed)); } static ssize_t max_speed_read_file(struct pci_slot *slot, char *buf) From patchwork Sat May 15 05:24:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259443 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 1FEB7C43460 for ; Sat, 15 May 2021 05:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA8EC613CE for ; Sat, 15 May 2021 05:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbhEOFZy (ORCPT ); Sat, 15 May 2021 01:25:54 -0400 Received: from mail-ed1-f45.google.com ([209.85.208.45]:43649 "EHLO mail-ed1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbhEOFZx (ORCPT ); Sat, 15 May 2021 01:25:53 -0400 Received: by mail-ed1-f45.google.com with SMTP id s6so830227edu.10 for ; Fri, 14 May 2021 22:24:40 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EQ3R2W3kyD0ic+vfu4svsuSqjX5xIeVtIEqsI3c2288=; b=DpRrOO3AZ5PJE8/gObClbb9i6AaESRu2TNY9LBZakbGz2O/xj7u29DrcxLlhIXZt2c qw4JWaNtos4giZi7NECQqtGaj8LohJID1JDEBst0wNXderw9nt8id6HrCFePiWw7IaPp h2AGGLwejQEENKMNxpeHBosz1jHei1M0RSJrCy8exmdPs1FC79XBISx80Ki0pCajWhzN DIa/WsjlHQ5NcsvkxlqbxpVhlJo2fkhejuPjm6MrkdQgq6U7L+GLmLm9CUOpHCFDuiUZ eQAKBPBMRbWxPo5foCEcKsS2GNGvt9sTp5pLjXlmEdWw40/dWWE+3fkNq2728jD/AaXH fIPw== X-Gm-Message-State: AOAM531wdqi/iezyM3fObXM6D98kU8uMWRee0URCq6PK0vBnWiFMuu/d 3101r8qlJ9eA4NA3QYFoYaU= X-Google-Smtp-Source: ABdhPJxnsAptxOx/HBJpYKJDCOzTTrrz2+pFB3BqgI1f0hBvz5p50K52vu7dJoKs7QYOOJjk4VYp9w== X-Received: by 2002:a05:6402:100c:: with SMTP id c12mr42219916edu.165.1621056279708; Fri, 14 May 2021 22:24:39 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:39 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 04/14] PCI/MSI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:24 +0000 Message-Id: <20210515052434.1413236-4-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 217dc9f0231f..dbfec59dfe41 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -465,8 +465,8 @@ static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr, entry = irq_get_msi_desc(irq); if (entry) - return sprintf(buf, "%s\n", - entry->msi_attrib.is_msix ? "msix" : "msi"); + return sysfs_emit(buf, "%s\n", + entry->msi_attrib.is_msix ? "msix" : "msi"); return -ENODEV; } From patchwork Sat May 15 05:24:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259445 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 B7B43C433ED for ; Sat, 15 May 2021 05:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 966A4613CE for ; Sat, 15 May 2021 05:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbhEOFZ4 (ORCPT ); Sat, 15 May 2021 01:25:56 -0400 Received: from mail-ed1-f54.google.com ([209.85.208.54]:33715 "EHLO mail-ed1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbhEOFZz (ORCPT ); Sat, 15 May 2021 01:25:55 -0400 Received: by mail-ed1-f54.google.com with SMTP id b17so906632ede.0 for ; Fri, 14 May 2021 22:24:41 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=XaBjjWzOw5dvTDC+qJZK86V8BlRmiuqHS5dgLumUkUo=; b=mGfyu4jrPv2viwCNu5P38hAx2GUqdLZM0A0DHJC43KtogkEGDXnzaSK9Bo3E6crFu4 mGrdy9vOTAyoP2EXwxc1NYnyezJlPKVdfFigAjAaPa7TCmcB+NYn9bsslaPwEJYRL3uM ShlNlDAJ0JrSsZXlkYL5+pK5gFj6wkQSxmZUXilF9i0W+M8wA/hv3yghvcv9q2T6h+VE 5Ck/kMzHHHryIU0UCU/GdPBz4EtwrYkANGfuGRpKF9n3T6wtOTyLsx7/LKWZlv96oTBa cGpVwUmYrnRxd8wS+/EwTPIcTTaTxjOo/ulPu3HEg9ehvurWiEbRld0MFf6FVFIEp9lO k0tA== X-Gm-Message-State: AOAM533ygRM9QpGw2nvEBFPB0GkYqHrDBesbJmmkJp1Srr23JURfUbvz DT0R9meAVOHJgGEEPydFHDo= X-Google-Smtp-Source: ABdhPJyAvW2Dm++VEmuqwcgqr9Jm9cUso1ruNLB2gDuMwnIl6aOLUg/209jLCyYGsCqG4kFGPH3syQ== X-Received: by 2002:a05:6402:4392:: with SMTP id o18mr20003141edc.58.1621056280892; Fri, 14 May 2021 22:24:40 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:40 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 05/14] PCI/IOV: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:25 +0000 Message-Id: <20210515052434.1413236-5-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/iov.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index afc06e6ce115..a71258347323 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -346,7 +346,7 @@ static ssize_t sriov_totalvfs_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); + return sysfs_emit(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); } static ssize_t sriov_numvfs_show(struct device *dev, @@ -361,7 +361,7 @@ static ssize_t sriov_numvfs_show(struct device *dev, num_vfs = pdev->sriov->num_VFs; device_unlock(&pdev->dev); - return sprintf(buf, "%u\n", num_vfs); + return sysfs_emit(buf, "%u\n", num_vfs); } /* @@ -435,7 +435,7 @@ static ssize_t sriov_offset_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->offset); + return sysfs_emit(buf, "%u\n", pdev->sriov->offset); } static ssize_t sriov_stride_show(struct device *dev, @@ -444,7 +444,7 @@ static ssize_t sriov_stride_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->stride); + return sysfs_emit(buf, "%u\n", pdev->sriov->stride); } static ssize_t sriov_vf_device_show(struct device *dev, @@ -453,7 +453,7 @@ static ssize_t sriov_vf_device_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%x\n", pdev->sriov->vf_device); + return sysfs_emit(buf, "%x\n", pdev->sriov->vf_device); } static ssize_t sriov_drivers_autoprobe_show(struct device *dev, @@ -462,7 +462,7 @@ static ssize_t sriov_drivers_autoprobe_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe); + return sysfs_emit(buf, "%u\n", pdev->sriov->drivers_autoprobe); } static ssize_t sriov_drivers_autoprobe_store(struct device *dev, From patchwork Sat May 15 05:24:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259447 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 415E1C43461 for ; Sat, 15 May 2021 05:24:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E5B3613CE for ; Sat, 15 May 2021 05:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231625AbhEOFZ4 (ORCPT ); Sat, 15 May 2021 01:25:56 -0400 Received: from mail-ed1-f43.google.com ([209.85.208.43]:40523 "EHLO mail-ed1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232412AbhEOFZ4 (ORCPT ); Sat, 15 May 2021 01:25:56 -0400 Received: by mail-ed1-f43.google.com with SMTP id t3so850017edc.7 for ; Fri, 14 May 2021 22:24:42 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=1ES7VTSt0mLOOOtyK1uMH/ESz61Of936G331zCp64LY=; b=JDQA6nBvPtxRWn/DSVCzYjYjSb3P016ZXgQYrZUIdqw1b/m7op6m2XLuQ4jPRNQgrM aLce0SWkgIydaXXxxpJDPXP/8rT4Xzz/CISfLxBIFuAvvtuJEOVn8vtDely0tSZvZgCW Tpkn5VMXBY8fY3LxytEr7Es8m0HEOC5KPpQ9GTrXVwxiKZpza7bHG3a3aYBCu0rTwlON RDvM957m8wIzXEu1cTkowKICu22cgR5weJGIIvZ3YPntRusfKyFnc9o0RvGkM2FoO78W LrmxaJFLJiUUS1T0WErph81SSznqnXAt23WdJv5CaJ5/AYhOLQFIaIJwrZdNamJiLehS DV8w== X-Gm-Message-State: AOAM533Lx1L1xqzOlrvrTd9sRjMucuot6jWoKj+kvT4x6S1PP/An0OUI Rxequm71barDd7AB8gzz8gI= X-Google-Smtp-Source: ABdhPJygPIcpBCKLUs50yfnaIlQr7YwzdjdoLmzwNRzphOsHpcVXycakggcgTJ5RAMyt0x096OU7mw== X-Received: by 2002:aa7:d893:: with SMTP id u19mr15024467edq.258.1621056281879; Fri, 14 May 2021 22:24:41 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:41 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 06/14] PCI/P2PDMA: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:26 +0000 Message-Id: <20210515052434.1413236-6-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/p2pdma.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 196382630363..a1351b3e2c4c 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -53,7 +53,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr, if (pdev->p2pdma->pool) size = gen_pool_size(pdev->p2pdma->pool); - return scnprintf(buf, PAGE_SIZE, "%zd\n", size); + return sysfs_emit(buf, "%zd\n", size); } static DEVICE_ATTR_RO(size); @@ -66,7 +66,7 @@ static ssize_t available_show(struct device *dev, struct device_attribute *attr, if (pdev->p2pdma->pool) avail = gen_pool_avail(pdev->p2pdma->pool); - return scnprintf(buf, PAGE_SIZE, "%zd\n", avail); + return sysfs_emit(buf, "%zd\n", avail); } static DEVICE_ATTR_RO(available); @@ -75,8 +75,7 @@ static ssize_t published_show(struct device *dev, struct device_attribute *attr, { struct pci_dev *pdev = to_pci_dev(dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", - pdev->p2pdma->p2pmem_published); + return sysfs_emit(buf, "%d\n", pdev->p2pdma->p2pmem_published); } static DEVICE_ATTR_RO(published); From patchwork Sat May 15 05:24:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259449 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 CB0F6C433B4 for ; Sat, 15 May 2021 05:24:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF158613CE for ; Sat, 15 May 2021 05:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbhEOFZ5 (ORCPT ); Sat, 15 May 2021 01:25:57 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:45047 "EHLO mail-ed1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232787AbhEOFZ4 (ORCPT ); Sat, 15 May 2021 01:25:56 -0400 Received: by mail-ed1-f50.google.com with SMTP id t15so828220edr.11 for ; Fri, 14 May 2021 22:24:43 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=NDGawuhAJJmz73B7uj32A5EHuzQVuuXCnB1idlmDenc=; b=NTfUVMakU1xg/KSu37r5IiqxIYmXFLm0lv53yKox70PP0yIpfLeHa//gD76xOn6cmp ruap9gnLdssb+ChRyPcoRoDFdDw2fShfTEgkVOtZw7hiXEP+crOxbbCIYE1iUm01cF4Y WdNBvCNta/z9MrpeU8hdWY+UgaysPPxMKf0YNEntxdhz/JxjjnDCib/AVsd96PocQ0sz CTWg2AAC+O+FdiYtsFJvaKrMQNmCeLyKSwTN4GZ1qvF6pzNfdKzOYlot3zLcvwcQKO/a pEGtfTJUfltpX5USbQFNzIc7ApPiipEWdyOojW0OWV+sv7TVx8vfxKd+SdI2H2exQl8b JXbg== X-Gm-Message-State: AOAM531VChJgeuXYvDkVQYOtwLs6jdTHUxijn3NjUxCi7D4ny3lti/IV Ec76Ov8P3J3NUnYzXvXGe3A= X-Google-Smtp-Source: ABdhPJzcnqJKKGPYI8WdNfgX818BwDGlEuupjGLdvu+Xy2bDDyUqLFOB8dxZzlqJlTMV6KHDrrBVZQ== X-Received: by 2002:a50:fe8c:: with SMTP id d12mr60525536edt.336.1621056282857; Fri, 14 May 2021 22:24:42 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:42 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 07/14] PCI/ASPM: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:27 +0000 Message-Id: <20210515052434.1413236-7-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pcie/aspm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index ac0557a305af..013a47f587ce 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1208,7 +1208,7 @@ static ssize_t aspm_attr_show_common(struct device *dev, struct pci_dev *pdev = to_pci_dev(dev); struct pcie_link_state *link = pcie_aspm_get_link(pdev); - return sprintf(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0); + return sysfs_emit(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0); } static ssize_t aspm_attr_store_common(struct device *dev, @@ -1265,7 +1265,7 @@ static ssize_t clkpm_show(struct device *dev, struct pci_dev *pdev = to_pci_dev(dev); struct pcie_link_state *link = pcie_aspm_get_link(pdev); - return sprintf(buf, "%d\n", link->clkpm_enabled); + return sysfs_emit(buf, "%d\n", link->clkpm_enabled); } static ssize_t clkpm_store(struct device *dev, From patchwork Sat May 15 05:24:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259451 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 161D1C43460 for ; Sat, 15 May 2021 05:24:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFCA6613EB for ; Sat, 15 May 2021 05:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbhEOFZ6 (ORCPT ); Sat, 15 May 2021 01:25:58 -0400 Received: from mail-ed1-f46.google.com ([209.85.208.46]:43655 "EHLO mail-ed1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232432AbhEOFZ6 (ORCPT ); Sat, 15 May 2021 01:25:58 -0400 Received: by mail-ed1-f46.google.com with SMTP id s6so830313edu.10 for ; Fri, 14 May 2021 22:24:44 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Gp2LJL1lW12f9o9B/z7t/PXSY/mDvHIuRVwQfasUic=; b=uhDq1yDKpt08bswdcWli0d7GN/fXd5kPr9OVYqF0tDeShSJ/n42nY1GiQnJCFZ6oUe gQScMu+8/4FwcpWcI3LZOcwg9RvCW8DVmv+QJLwShCZaTKYyHYTfwN8wkN/ABx/p+5T1 GHAYoVg1pd0hi7llsFOLlwMB1qQ0dzy6/695Fo3qbwkCDGzGgJLdIvv5Du0gNi9JUxNT BAwBjSySN5eM6VYi+ZkrFJR7tSJSt6yOA2AR1/OWLRwtZ3zE8LwnuQK+mOjtXQ3sCzG0 7dcetYbtDkyaKMBQd902ZIJgj4AUg5d0yHsgbau6M/GUvW6Fxsnssr5zq6aMpnWv6itO /w0w== X-Gm-Message-State: AOAM533FnqyDMYVjQZOsitXC0f8Q+H/TIEifgU5toEbe5rUfnp8bjlzW k9vEvV7SZBZrNncbi80pbM8= X-Google-Smtp-Source: ABdhPJygjYsZin7lnJ61Xk7tN8Ajfd+LkXB3aIY5KrQ/tbUiVN1ghVgMxSTrTAGQmmN8ZvQkot3ULQ== X-Received: by 2002:a50:ec89:: with SMTP id e9mr59801846edr.347.1621056283909; Fri, 14 May 2021 22:24:43 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:43 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 08/14] PCI: switchtec: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:28 +0000 Message-Id: <20210515052434.1413236-8-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/switch/switchtec.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c index ba52459928f7..0b301f8be9ed 100644 --- a/drivers/pci/switch/switchtec.c +++ b/drivers/pci/switch/switchtec.c @@ -280,7 +280,7 @@ static ssize_t device_version_show(struct device *dev, ver = ioread32(&stdev->mmio_sys_info->device_version); - return sprintf(buf, "%x\n", ver); + return sysfs_emit(buf, "%x\n", ver); } static DEVICE_ATTR_RO(device_version); @@ -292,7 +292,7 @@ static ssize_t fw_version_show(struct device *dev, ver = ioread32(&stdev->mmio_sys_info->firmware_version); - return sprintf(buf, "%08x\n", ver); + return sysfs_emit(buf, "%08x\n", ver); } static DEVICE_ATTR_RO(fw_version); @@ -344,7 +344,7 @@ static ssize_t component_vendor_show(struct device *dev, /* component_vendor field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "none\n"); + return sysfs_emit(buf, "none\n"); return io_string_show(buf, &si->gen3.component_vendor, sizeof(si->gen3.component_vendor)); @@ -359,9 +359,9 @@ static ssize_t component_id_show(struct device *dev, /* component_id field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "none\n"); + return sysfs_emit(buf, "none\n"); - return sprintf(buf, "PM%04X\n", id); + return sysfs_emit(buf, "PM%04X\n", id); } static DEVICE_ATTR_RO(component_id); @@ -373,9 +373,9 @@ static ssize_t component_revision_show(struct device *dev, /* component_revision field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "255\n"); + return sysfs_emit(buf, "255\n"); - return sprintf(buf, "%d\n", rev); + return sysfs_emit(buf, "%d\n", rev); } static DEVICE_ATTR_RO(component_revision); @@ -384,7 +384,7 @@ static ssize_t partition_show(struct device *dev, { struct switchtec_dev *stdev = to_stdev(dev); - return sprintf(buf, "%d\n", stdev->partition); + return sysfs_emit(buf, "%d\n", stdev->partition); } static DEVICE_ATTR_RO(partition); @@ -393,7 +393,7 @@ static ssize_t partition_count_show(struct device *dev, { struct switchtec_dev *stdev = to_stdev(dev); - return sprintf(buf, "%d\n", stdev->partition_count); + return sysfs_emit(buf, "%d\n", stdev->partition_count); } static DEVICE_ATTR_RO(partition_count); From patchwork Sat May 15 05:24:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259453 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 D61E2C433ED for ; Sat, 15 May 2021 05:24:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB7C7613CE for ; Sat, 15 May 2021 05:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbhEOFZ6 (ORCPT ); Sat, 15 May 2021 01:25:58 -0400 Received: from mail-ed1-f48.google.com ([209.85.208.48]:34491 "EHLO mail-ed1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbhEOFZ6 (ORCPT ); Sat, 15 May 2021 01:25:58 -0400 Received: by mail-ed1-f48.google.com with SMTP id l7so874933edb.1 for ; Fri, 14 May 2021 22:24:45 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=JeL2FUARGxszhpfrtswg3uTFL3yp7K/KDjvHQpNvygA=; b=MpOHcu6+X96PDBYf3RHuK8iZqE5riPmBskBF/ZM8juOWQ72y7szNniKe206+RW6c+J 5g86iFTjXPt7p/1mLlMtnaMYMlHLL0dlUcd7HTjssY9RpKK2GssTI2aVEyF6/3jKKzQp fvtF9/3ZLxLs1TCrVvAHU02zFpVBLq6tcLuix/HvE8iVnMlDg+aLKpiSuoE8TiIuPhMv GOzKpNqpJyqcthn9GK0efaMXTidNmnrV6st/4x5wItAmjcFg98X2+56Yr8prXvPEiTup eiZOyL/w5wuL/pJL1rvt0hYDU49+lYaVxpO8YEFxmRkHBQ4WFRWETWcCJgkdZDmaZU6W ZYEA== X-Gm-Message-State: AOAM53086Sub3WhPVAG9sST3rG1DN05tupxh7avjEBEdSAMI81N6sy1x P1WE0ECi180mck9WgjPyzww= X-Google-Smtp-Source: ABdhPJx+4BP4JtYzZtC8In7d/GJnnFuTFXS/SOuG81dzRIapdNn/ATBw6N6OxyoSxAEY6QITNhVGvw== X-Received: by 2002:aa7:cc10:: with SMTP id q16mr39814486edt.53.1621056284880; Fri, 14 May 2021 22:24:44 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:44 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 09/14] PCI: rpadlpar: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:29 +0000 Message-Id: <20210515052434.1413236-9-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/rpadlpar_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c index dbfa0b55d31a..068b7810a574 100644 --- a/drivers/pci/hotplug/rpadlpar_sysfs.c +++ b/drivers/pci/hotplug/rpadlpar_sysfs.c @@ -50,7 +50,7 @@ static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, static ssize_t add_slot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "0\n"); + return sysfs_emit(buf, "0\n"); } static ssize_t remove_slot_store(struct kobject *kobj, @@ -80,7 +80,7 @@ static ssize_t remove_slot_store(struct kobject *kobj, static ssize_t remove_slot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "0\n"); + return sysfs_emit(buf, "0\n"); } static struct kobj_attribute add_slot_attr = From patchwork Sat May 15 05:24:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259455 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 293D7C433B4 for ; Sat, 15 May 2021 05:24:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DCA6613F7 for ; Sat, 15 May 2021 05:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233385AbhEOF0A (ORCPT ); Sat, 15 May 2021 01:26:00 -0400 Received: from mail-ed1-f43.google.com ([209.85.208.43]:39715 "EHLO mail-ed1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbhEOFZ7 (ORCPT ); Sat, 15 May 2021 01:25:59 -0400 Received: by mail-ed1-f43.google.com with SMTP id h16so852817edr.6 for ; Fri, 14 May 2021 22:24:46 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=DdJ+gi3kfx5UscQD8MEmkjatX64t7LAuyBsCWTQVyR4=; b=cSgh5F92aHHKIFOEmUMXybJkrQs83g4lAlR43AtZhaXt+7cNw5ys6DLZPV00LF1Zhg neA16UI8oMD88WiZuZVfRQQWj719dy3kfmYq3IA3oJfe6qO48Frvi6s6kUgcFmi+gnnu zdlHVBmL4gLA3VIilMCNqFvg+cZ4iNT68I7fh1nh5qWMeUyIUofW4aTObVMynqW3tdCs ZF/zMGJZZ8tAiNDygFIZ7KFSIfgYXYLcjwxNlnKWjZCujkjJ1nYgVc0IJuPBInpqiV5P b/xRRzuu2fmDZRCJyipZ8K/7b+BBwRftqon4NZLShiab4hsb/m1bzT75a6g+SWITwDis uTlw== X-Gm-Message-State: AOAM530Z3dPpLT2cmgtKkST9Z7w+e4UqCF+Kky0Rq74mfBYksLusrVrj B4bcH5/Ol+LDGT3XdTfhwgk= X-Google-Smtp-Source: ABdhPJwUFEaurmP9EKuuMm+T/D2jN40L9mLA9g5wzTrmHUIny74d+EPyB5vutIYIvhUmd0UAv1N90w== X-Received: by 2002:a50:ab06:: with SMTP id s6mr50742980edc.100.1621056285971; Fri, 14 May 2021 22:24:45 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:45 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 10/14] PCI: hotplug: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:30 +0000 Message-Id: <20210515052434.1413236-10-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/pci_hotplug_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index 5ac31f683b85..058d5937d8a9 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -73,7 +73,7 @@ static ssize_t power_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, @@ -130,7 +130,7 @@ static ssize_t attention_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf, @@ -175,7 +175,7 @@ static ssize_t latch_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static struct pci_slot_attribute hotplug_slot_attr_latch = { @@ -192,7 +192,7 @@ static ssize_t presence_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static struct pci_slot_attribute hotplug_slot_attr_presence = { From patchwork Sat May 15 05:24:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259457 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 07B53C433ED for ; Sat, 15 May 2021 05:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E13EE613F7 for ; Sat, 15 May 2021 05:24:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232714AbhEOF0B (ORCPT ); Sat, 15 May 2021 01:26:01 -0400 Received: from mail-ej1-f43.google.com ([209.85.218.43]:37589 "EHLO mail-ej1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233173AbhEOF0B (ORCPT ); Sat, 15 May 2021 01:26:01 -0400 Received: by mail-ej1-f43.google.com with SMTP id w3so1601436ejc.4 for ; Fri, 14 May 2021 22:24:47 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=O4j5vWKcpf1/fXayhp3JqEGpiyWg4HsxhuOtNpqA8wo=; b=MT3K1uJR8jhomFVAZv1p8aE1ZQB70k7XGENZyF4W+WysX5tXmxZdnEGtVca88Jn7j0 sHH7OJlDiTMoUOULEZsrN/NUhEvhnuujc6WT8Ij+im/3jR9/rto0YpTLiVJqcny3I/uL vd2DlcA68fYFGGoqwvSkaN2xfyLO3ORInEdg/4qxreuSQ6USY26NA1WbfCYV2q1+dYuh 6eZAdMsA++Mb+ynN4S8EORfgjpf2PSBWamT+bIVg79Du7jZcGPfXNnsxvBhlQp6jwmDh JA/2R4pYS/0g7RjPiuiRiy1Wm4Z4azhphIxc6TpGgUfDxPLggvhrLcG4adAn9PcZunS0 s6EA== X-Gm-Message-State: AOAM530RS2nsDn0HDMobhbbWSXnoYXuwT89+Az8+rFQNm/ouYj2n193+ BGS5zSWAVsztG9qtHS6GBlw= X-Google-Smtp-Source: ABdhPJzLfDPuTOgIrRqYiui9dXEh/ZAVy0flFmqCN22LEo3CBQNC7QrZjxzGfkQ+eGOXwrKfmjn3Vg== X-Received: by 2002:a17:906:dc4c:: with SMTP id yz12mr2396563ejb.364.1621056286994; Fri, 14 May 2021 22:24:46 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:46 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 11/14] PCI: shpchp: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Sat, 15 May 2021 05:24:31 +0000 Message-Id: <20210515052434.1413236-11-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/shpchp_sysfs.c | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c index 45658bb5c554..64beed7a26be 100644 --- a/drivers/pci/hotplug/shpchp_sysfs.c +++ b/drivers/pci/hotplug/shpchp_sysfs.c @@ -24,50 +24,54 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev; - char *out = buf; int index, busnr; struct resource *res; struct pci_bus *bus; + size_t len = 0; pdev = to_pci_dev(dev); bus = pdev->subordinate; - out += sprintf(buf, "Free resources: memory\n"); + len += sysfs_emit_at(buf, len, "Free resources: memory\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_MEM) && !(res->flags & IORESOURCE_PREFETCH)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, + "start = %8.8llx, length = %8.8llx\n", + (unsigned long long)res->start, + (unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: prefetchable memory\n"); + len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_MEM) && (res->flags & IORESOURCE_PREFETCH)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, + "start = %8.8llx, length = %8.8llx\n", + (unsigned long long)res->start, + (unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: IO\n"); + len += sysfs_emit_at(buf, len, "Free resources: IO\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_IO)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, + "start = %8.8llx, length = %8.8llx\n", + (unsigned long long)res->start, + (unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: bus numbers\n"); + len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n"); for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) { if (!pci_find_bus(pci_domain_nr(bus), busnr)) break; } if (busnr < bus->busn_res.end) - out += sprintf(out, "start = %8.8x, length = %8.8x\n", - busnr, (int)(bus->busn_res.end - busnr)); + len += sysfs_emit_at(buf, len, + "start = %8.8x, length = %8.8x\n", + busnr, (int)(bus->busn_res.end - busnr)); - return out - buf; + return len; } static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL); From patchwork Sat May 15 05:24:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259459 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 A540CC433B4 for ; Sat, 15 May 2021 05:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D528613EB for ; Sat, 15 May 2021 05:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233013AbhEOF0C (ORCPT ); Sat, 15 May 2021 01:26:02 -0400 Received: from mail-ej1-f49.google.com ([209.85.218.49]:33514 "EHLO mail-ej1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbhEOF0B (ORCPT ); Sat, 15 May 2021 01:26:01 -0400 Received: by mail-ej1-f49.google.com with SMTP id z12so158784ejw.0 for ; Fri, 14 May 2021 22:24:48 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=B3UpkKoHQG0tf/oaVD2LnuLhgOWE3b/n2dCLRadGIF4=; b=ahth2oomvySxlOPGd0F0TyfCqfxt0RteEPKUxzAkRn41OL/6XkMAbBNdNP2rYLYfJE ZM4+Ga7k6K1VPU90w3frcK9QcxLyseLhtidLreZUOSZ6qjQ7u2/Ztr56ieP8T3MWqhVq fPZr0Eu/5aR+lqYnSm75WhbE7ZwLiu6u7mzEPTsqHjUtqK2gxFLeUrkcZ51pNQ4tNaHU vk1QWcGoiX1kkfEDBCoO31vdgMpAR8LRa13rg+CppkZPzzS2iiiTNcR3wDVg6YSvxb6X I/KBCrt+hCRnCRzQ8RLC+ecpR7xnel+W2G7EieS4aM9ABw/rd9kEwLFWrUIlODmy05Jr E1GQ== X-Gm-Message-State: AOAM531I7Dx4BhnIMeVcb3jhXxUy1hBC79E1Vs5Bm+z8Xz9ab7NMWwgA kTBLil5d6Nh2hTPSaRLp5Ic= X-Google-Smtp-Source: ABdhPJyGXrwiw6AUEQkiZNiiFMo18eHtQ1pD3BH99lSq0gDTyHGjespN0d9GO5o1Cd76Qnuv/DwQMA== X-Received: by 2002:a17:907:2646:: with SMTP id ar6mr19927960ejc.293.1621056288007; Fri, 14 May 2021 22:24:48 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:47 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 12/14] PCI: Fix trailing newline handling of resource_alignment_param Date: Sat, 15 May 2021 05:24:32 +0000 Message-Id: <20210515052434.1413236-12-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The value of the "resource_alignment" can be specified using a kernel command-line argument (using the "pci=resource_alignment=") or through the corresponding sysfs object under the /sys/bus/pci path. Currently, when the value is set via the kernel command-line argument, and then subsequently accessed through sysfs object, the value read back will not be correct, as per: # grep -oE 'pci=resource_alignment.+' /proc/cmdline pci=resource_alignment=20@00:1f.2 # cat /sys/bus/pci/resource_alignment 20@00:1f. This is also true when the value is set through the sysfs object, but the trailing newline has not been included, as per: # echo -n 20@00:1f.2 > /sys/bus/pci/resource_alignment # cat /sys/bus/pci/resource_alignment 20@00:1f. When the value set through the sysfs object includes the trailing newline, then reading it back will work as intended, as per: # echo 20@00:1f.2 > /sys/bus/pci/resource_alignment # cat /sys/bus/pci/resource_alignment 20@00:1f.2 To fix this inconsistency, append a trailing newline in the show() function and strip the trailing line in the store() function if one is present. Also, allow for the value previously set using either a command-line argument or through the sysfs object to be cleared at run-time. Fixes: e499081da1a2 ("PCI: Force trailing new line to resource_alignment_param in sysfs") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5ed316ea5831..7cde86bdcc8e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6439,34 +6439,37 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) spin_lock(&resource_alignment_lock); if (resource_alignment_param) - count = sysfs_emit(buf, "%s", resource_alignment_param); + count = sysfs_emit(buf, "%s\n", resource_alignment_param); spin_unlock(&resource_alignment_lock); - /* - * When set by the command line, resource_alignment_param will not - * have a trailing line feed, which is ugly. So conditionally add - * it here. - */ - if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) { - buf[count - 1] = '\n'; - buf[count++] = 0; - } - return count; } static ssize_t resource_alignment_store(struct bus_type *bus, const char *buf, size_t count) { - char *param = kstrndup(buf, count, GFP_KERNEL); + char *param, *old, *end; + param = kstrndup(buf, count, GFP_KERNEL); if (!param) return -ENOMEM; + end = strchr(param, '\n'); + if (end) + *end = '\0'; + spin_lock(&resource_alignment_lock); - kfree(resource_alignment_param); - resource_alignment_param = param; + old = resource_alignment_param; + if (strlen(param)) { + resource_alignment_param = param; + } else { + kfree(resource_alignment_param); + resource_alignment_param = NULL; + } spin_unlock(&resource_alignment_lock); + + kfree(old); + return count; } From patchwork Sat May 15 05:24:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259463 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 134A7C43460 for ; Sat, 15 May 2021 05:24:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E945D613EB for ; Sat, 15 May 2021 05:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbhEOF0D (ORCPT ); Sat, 15 May 2021 01:26:03 -0400 Received: from mail-ej1-f54.google.com ([209.85.218.54]:39752 "EHLO mail-ej1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbhEOF0C (ORCPT ); Sat, 15 May 2021 01:26:02 -0400 Received: by mail-ej1-f54.google.com with SMTP id l1so1587216ejb.6 for ; Fri, 14 May 2021 22:24:49 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=8I9eAMgW1d5+6SXiSWDrf1uaChlCS5v9S4POj4RPQdA=; b=UEk43dBfc/9KXCdfGF+z5seRZrxKu9xlKXzTNfjpAyia2HRnCjzN8H+qYuPSptF2YE 99+XyD59ChD7Vf5TVjgZIuVIE7fho2KvF/ivfsGEH7Uo4qof8zay2SmEDQYyrT2JE5wl +geiG2Io2WbbfDf9dYX2kIfjiPik9SuyPU/bMu3BWlPRZueLVMEhA0TOTTGIWympyLc0 slZcxQi2KMIM3y0qZ6rJfvVKSTZAAYJLRLJaGKtjMsmPVn4/x3sD0PtEMTV4PSIEoBuJ z1mToWwgEZiArltxDvn11LMIDUuFXk2WJ4jzveC6/hY4pPf2fHdBR0EP9sYQ/NuDxhFK W0hw== X-Gm-Message-State: AOAM530+ctvKISsK6pc5eGGCVMRqNZF3yMbtAY0MZlUH56xT1Pl8aG8B iRAVM8Lk2A2bikzrUFbAC5o= X-Google-Smtp-Source: ABdhPJxvwuJ+Vc4f4aGryEC1IiRJpvd+1xHQx7CFoqRNrxuoykeL0ShP0qNJDTfuYBVia8rDk6gJDQ== X-Received: by 2002:a17:907:a06d:: with SMTP id ia13mr18482816ejc.484.1621056288974; Fri, 14 May 2021 22:24:48 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:48 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 13/14] PCI/sysfs: Add missing trailing newline to devspec_show() Date: Sat, 15 May 2021 05:24:33 +0000 Message-Id: <20210515052434.1413236-13-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org At the moment, when the value of the "devspec" sysfs object is read from the user space there will be no newline present, and the utilities such as the "cat" command won't display the result of the read correctly in a shell, as the trailing newline is currently missing. To fix this, append a newline character in the show() function. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index beb8d1f4fafe..5d63df7c1820 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -537,7 +537,7 @@ static ssize_t devspec_show(struct device *dev, if (np == NULL) return 0; - return sysfs_emit(buf, "%pOF", np); + return sysfs_emit(buf, "%pOF\n", np); } static DEVICE_ATTR_RO(devspec); #endif From patchwork Sat May 15 05:24:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12259461 X-Patchwork-Delegate: bhelgaas@google.com 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 1F89BC43462 for ; Sat, 15 May 2021 05:24:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 031E1613F7 for ; Sat, 15 May 2021 05:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233172AbhEOF0E (ORCPT ); Sat, 15 May 2021 01:26:04 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:45055 "EHLO mail-ed1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbhEOF0D (ORCPT ); Sat, 15 May 2021 01:26:03 -0400 Received: by mail-ed1-f50.google.com with SMTP id t15so828373edr.11 for ; Fri, 14 May 2021 22:24:50 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=l65J0VP8+dF+CzFmmf34XzBwKUAccEC4aN+sTYjEOtI=; b=hxF7q4W3+81vtr9Pf/coQ/wqxL4lziDEj9lHkM+bAQ1gjbiN50Xr188g0kc6p0Ab6V WWfblyT/Np6E7+0jGbHxH2f4YkL/7u8MPv9OOGUKuVVsXglc46SZDXoGd9exeg+Ds9nx +HusXOkl/hBlI1MDD0AjQBY49yi+69weiW2VHOtX3mjb8wYetnDksq3DM2EQderQmubi +sAgDtrhF1SSbvPpiFkXJV+E4R7FiRFSv42bFBU8JIjsTxZkQK7zVBt580K/D0o5vI9u pIHd6HaPBMon+t8OeRf0tCNUzk29KT949A4oa3WLfg6iY3HfZQpUy04Jt2pMYXfI67A5 E5Dg== X-Gm-Message-State: AOAM530rXAjheyD8rd5mtatdQZDeoPSIYZPKYhduRMLQVwm4wfO/Hdiw B8Xi0jWRPtQ51DjDaXsYatc= X-Google-Smtp-Source: ABdhPJxKOWt67s3c4arbmA4eCFVxbLX2nJU5TzBTB1JhkMEU3nW9uORpfOz85iSHSHEdXWViuNcVeA== X-Received: by 2002:a50:fc0b:: with SMTP id i11mr61231380edr.259.1621056289994; Fri, 14 May 2021 22:24:49 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id kt21sm4821487ejb.5.2021.05.14.22.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 22:24:49 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Logan Gunthorpe , Joe Perches , "Oliver O'Halloran" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Tyrel Datwyler , Russell Currey , Kurt Schwemmer , Vidya Sagar , Xiongfeng Wang , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 14/14] PCI/sysfs: Only show value when driver_override is not NULL Date: Sat, 15 May 2021 05:24:34 +0000 Message-Id: <20210515052434.1413236-14-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515052434.1413236-1-kw@linux.com> References: <20210515052434.1413236-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Only expose the value of the "driver_override" variable through the corresponding sysfs object when a value is actually set. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d63df7c1820..4e9f582ca10f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -580,10 +580,11 @@ static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); - ssize_t len; + ssize_t len = 0; device_lock(dev); - len = sysfs_emit(buf, "%s\n", pdev->driver_override); + if (pdev->driver_override) + len = sysfs_emit(buf, "%s\n", pdev->driver_override); device_unlock(dev); return len; }