From patchwork Tue May 18 03:40:56 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: 12263463 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 68F0CC433B4 for ; Tue, 18 May 2021 03:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 349CA60FF3 for ; Tue, 18 May 2021 03:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242773AbhERDmd (ORCPT ); Mon, 17 May 2021 23:42:33 -0400 Received: from mail-lf1-f54.google.com ([209.85.167.54]:44995 "EHLO mail-lf1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235384AbhERDm3 (ORCPT ); Mon, 17 May 2021 23:42:29 -0400 Received: by mail-lf1-f54.google.com with SMTP id j6so9270961lfr.11 for ; Mon, 17 May 2021 20:41:12 -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=18Y77oCkwmGvKixeQ8r3dtdgUXHABcaq/TVHul58ByE=; b=linMW9O9hMzqlNBzdR6CRNQv8R4XUjW/xZU+g/1tJ4OV8rocIVv86HUSCIgP1CQ7TR pieeNvQs3MOCXiowyR5lVCYhrgPpQWSbrXK+ao8CtmnjnAUiSs+S9MWl4h+th9jpvRSU BKvCxWsvNocLgsNPMV2xhtEg2Q+x763QAJ8qKcTlD0IX0ptojojJy25wQnMSX7jlemTj 7iOCJy0twYFgRoT4SE522HByZ0U9LSQXxqv6DFvuRAvzLNOMBxVG1JFuGGfrcXx9+HUc h3w2TiKVp7A1iAnthslilJebHSYJRnx+Ka8heH9C6Os9w5UmSQCLqNmjz+auEy+pg0R3 HKdQ== X-Gm-Message-State: AOAM53147VUrQKDwE2fYXEAbjXns8j4aFbppeQcqVWZTkvcZCAtyR6Qt 2eXPd9KMZ0R/LGzrV/03rqM= X-Google-Smtp-Source: ABdhPJxoyKiwli9hkNKwxKAvkjbwumSx+iPEA4tkYHM8BczY2J321K7AjH7CzkTfCjq+ZYOK6wJleQ== X-Received: by 2002:a05:6512:1194:: with SMTP id g20mr404875lfr.407.1621309271509; Mon, 17 May 2021 20:41:11 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:10 -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 Subject: [PATCH v3 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:40:56 +0000 Message-Id: <20210518034109.158450-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 --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:40:57 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: 12263465 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 95147C433ED for ; Tue, 18 May 2021 03:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FBEA6135F for ; Tue, 18 May 2021 03:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235384AbhERDme (ORCPT ); Mon, 17 May 2021 23:42:34 -0400 Received: from mail-lj1-f177.google.com ([209.85.208.177]:37686 "EHLO mail-lj1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238463AbhERDmc (ORCPT ); Mon, 17 May 2021 23:42:32 -0400 Received: by mail-lj1-f177.google.com with SMTP id e2so3469464ljk.4 for ; Mon, 17 May 2021 20:41:13 -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=GKjtHEVtxnLS8r1kymvkicKwzLKGSRDQgyjURpCSGE4=; b=KvXZ3oA/eGRi2icy2728g8LdxHr4NpRmC7nb/g1lxh9chlReWL8Q6qUCAXvFc5d7c2 k6aW7tOrN+K8Cmb4kfSlAF+WZyZknnFyUeebCJDaFucpzxs6i/y+EuRyzbv9UMMS+HxJ wf60iABeaDgRjJvsadR4/w3wZXkWMdzmjfP95sr38kZfUvjloXfgDLlVwmOvty9IGZ+E sxToOYQekuUzyk/wj1r915FaQ0XjpzOqcHsCKNqvXgF08KAxklVpp/Q3CSOIumDz+fz5 2UivhQLji90ApglCKyP088vxeb4sxYRPVg3XL5IDE2fa9/j2nm6oPkhUYV6iwh8srFFm /wfQ== X-Gm-Message-State: AOAM531vRXlYFrRjjJGqlCIBPWHv8BUgDyxuom5oG8Nn4UYmMRngq3CR HKO3MAwQrorSauCDNIqVnp0= X-Google-Smtp-Source: ABdhPJxneHdUKCsFTAaoh4RJwYcn7zjWDxwvTeEGtdFkCKVVSdyq9+WBH5yZFOylpAYViMdON+dLrQ== X-Received: by 2002:a2e:9796:: with SMTP id y22mr2390310lji.70.1621309272657; Mon, 17 May 2021 20:41:12 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:12 -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 Subject: [PATCH v3 02/14] PCI/AER: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:40:57 +0000 Message-Id: <20210518034109.158450-2-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:40:58 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: 12263469 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 0E561C43460 for ; Tue, 18 May 2021 03:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D880761285 for ; Tue, 18 May 2021 03:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238463AbhERDme (ORCPT ); Mon, 17 May 2021 23:42:34 -0400 Received: from mail-lj1-f170.google.com ([209.85.208.170]:34538 "EHLO mail-lj1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240994AbhERDmd (ORCPT ); Mon, 17 May 2021 23:42:33 -0400 Received: by mail-lj1-f170.google.com with SMTP id b12so2550289ljp.1 for ; Mon, 17 May 2021 20:41:15 -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=/WKcZ2buTC8QjlU8EYmZoE/Ho3jV5zhXARvIjdslqQA=; b=LmtvhRwSRUMR0XMCtWLK+QA/V0uxUn7rKyfloA5ZfgAp4TA0NlGjWm7QKRoPIVRMIn vCRpg8oeysrQ1HNXCVcCC/EsX8xeETz0BVuosYKcIGSRPJb7BKVlZEnwOI7euafY4JCb ydafQdSoGopYX+gr42/lNw2NOvWw4EltxQZNlqBnNNRCHADuPIfZW67uVQ73/CkYfTM2 IctVfpllNxHaPfBpUDz8fAXlShotHr8sQi9rQiqC8b2FUJJwz1xl/fAqvMXiZ/NvoTv6 bU9KYDW6UHOqNGfEyFo9ceBE2wnqvcKfLL2w3/lcLK/Anwdz7iuS3wYizwjFFL+xcxPc huqw== X-Gm-Message-State: AOAM53253ZCcA3AIX22Ay+ZOl5U+dYNyfe/nN/s7kS0WkxuhzYPIewGD 6GQ7hUKJCwQbSPTJp+AA7Js= X-Google-Smtp-Source: ABdhPJwmgKtgn+z0DVZCjCQ6tXlBf8RrkF/TT+4kv3wdf1d33A5SclWptHbWJsQ9/JqxdOM2aEi4YA== X-Received: by 2002:a2e:6c0c:: with SMTP id h12mr2396434ljc.278.1621309273666; Mon, 17 May 2021 20:41:13 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:13 -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 Subject: [PATCH v3 03/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:40:58 +0000 Message-Id: <20210518034109.158450-3-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". Change style to the preferred one in the drivers/pci/slot.c file. drivers/pci/pci-label.c | 18 ++++++++++-------- drivers/pci/slot.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 17 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..751a26668e3a 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); - else - return sprintf(buf, "%04x:%02x:%02x\n", - pci_domain_nr(slot->bus), - slot->bus->number, - slot->number); + return sysfs_emit(buf, "%04x:%02x\n", + pci_domain_nr(slot->bus), + slot->bus->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 Tue May 18 03:40:59 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: 12263473 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 2C950C43470 for ; Tue, 18 May 2021 03:41:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3200611BE for ; Tue, 18 May 2021 03:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242962AbhERDmg (ORCPT ); Mon, 17 May 2021 23:42:36 -0400 Received: from mail-lf1-f51.google.com ([209.85.167.51]:44997 "EHLO mail-lf1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241281AbhERDmd (ORCPT ); Mon, 17 May 2021 23:42:33 -0400 Received: by mail-lf1-f51.google.com with SMTP id j6so9271044lfr.11 for ; Mon, 17 May 2021 20:41:15 -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=4hL2jDaypxg6i6aaRUuht27oQUPjguMBMeKYJncYE6k=; b=QM7ZrVqz2kgve3HMM/BiYwLdgRIiqwoiXBPGLkMFHXAA2FSITo3BBBEsEIi1Ngcawu zIS8jhAabOl4DNC5cjKIa7kGts4n0fYHNSX5kskdijlx62QsDZnrMLWsQhn2yLI/4fjY tvD/aiLNbAM45Crr+xUFGhhP2YcfEKHglGzO5gyccrhs4Cv/AjoeA9b341+AruqHxPg6 Nw+15Mnh6MNCsbmL0N75zLstehAj70NIyJhGnEUuaeBLwvqnNKpJLBQg8NduTLoz17hx IaJDg1vX1jTLchuWft28gdC1WswqzqvmKTax4yc4S3clP9Z7xZix5Hk8p64W5U9Ai0r+ QMLg== X-Gm-Message-State: AOAM533FznZawNBxRF0EjQtyIsV836QlCsXee2XY6N63nLo3SYqeIR0P QvhKB827KKNPHZhogOdnfW4= X-Google-Smtp-Source: ABdhPJwCW8uApyZg8BIkmXjJc8Nwhz2kbUupfsx8l5aSWwJrrWH6KQWkSU6hufwrlqwFfJ/+UPNwog== X-Received: by 2002:ac2:5a47:: with SMTP id r7mr2688265lfn.138.1621309274663; Mon, 17 May 2021 20:41:14 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:14 -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 Subject: [PATCH v3 04/14] PCI/MSI: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:40:59 +0000 Message-Id: <20210518034109.158450-4-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". Change style to preferred one as per Joe Perches' suggestion. drivers/pci/msi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 217dc9f0231f..9232255c8515 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -464,11 +464,11 @@ static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr, return retval; entry = irq_get_msi_desc(irq); - if (entry) - return sprintf(buf, "%s\n", - entry->msi_attrib.is_msix ? "msix" : "msi"); + if (!entry) + return -ENODEV; - return -ENODEV; + return sysfs_emit(buf, "%s\n", + entry->msi_attrib.is_msix ? "msix" : "msi"); } static int populate_msi_sysfs(struct pci_dev *pdev) From patchwork Tue May 18 03:41:00 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: 12263467 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 9A9C4C43461 for ; Tue, 18 May 2021 03:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71B4E611CC for ; Tue, 18 May 2021 03:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242900AbhERDmf (ORCPT ); Mon, 17 May 2021 23:42:35 -0400 Received: from mail-lj1-f173.google.com ([209.85.208.173]:33526 "EHLO mail-lj1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241948AbhERDmd (ORCPT ); Mon, 17 May 2021 23:42:33 -0400 Received: by mail-lj1-f173.google.com with SMTP id o8so9845554ljp.0 for ; Mon, 17 May 2021 20:41:16 -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=Ifk2YkSOqQpMJ9eIsFLnDFbL8FFLwhL1Jb7MgPI/dEI=; b=SIoCjx86iOBaYux5zz808f46QfGMDH4g7Xw1YHvS2q1txBuVHKM/5LeX95Kj5MWzvx B4dErXetFkRpXR1RuFU7Pr9Pk8Tc1oX5IbamXmu8Sh1uAIKfXFHSxWSRqSBF84wqrFPO u+ra5WRyL5sx1aOEX9QsnY8Mhkk1/cCpwIfhxQBZcIkTfoF2w5EyOyAhIDZFIfrdadEN Rdm4lB92QyFji/7e4uZxtmUJV1ka2BcZAVID2wvC1RVjGdA3gniCdb+izj9OZE7GTc5x lVj/DjcdiK9BhGGl7MVx9QRYrT4VK8hTUlazfLRJKBg83DKOcg5YShj2QFnh+EQfkjTn EBKw== X-Gm-Message-State: AOAM533tCLRtCcRo8GBSAu4do62qLM5sRv119S6npxh6DLm7o57+Qa3t PILQGOQN3KqfO6+Y4otKC30= X-Google-Smtp-Source: ABdhPJzPUZOjS9/ZOs/DECq+1zNXpZQh4Vaf4qlznc+fZJxcJLIQnk5sYJYW+bkteJEXjFM1IG56gw== X-Received: by 2002:a2e:5c83:: with SMTP id q125mr2287393ljb.447.1621309275684; Mon, 17 May 2021 20:41:15 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:15 -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 Subject: [PATCH v3 05/14] PCI/IOV: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:00 +0000 Message-Id: <20210518034109.158450-5-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:01 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: 12263471 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 CC37FC433B4 for ; Tue, 18 May 2021 03:41:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A23F861354 for ; Tue, 18 May 2021 03:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241948AbhERDmg (ORCPT ); Mon, 17 May 2021 23:42:36 -0400 Received: from mail-lj1-f170.google.com ([209.85.208.170]:36823 "EHLO mail-lj1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242825AbhERDmf (ORCPT ); Mon, 17 May 2021 23:42:35 -0400 Received: by mail-lj1-f170.google.com with SMTP id 131so9785552ljj.3 for ; Mon, 17 May 2021 20:41:17 -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=HqYmqxNMbxWuoyLabOZEnnEKr6vIaWZ62QE5jmH/JUM=; b=RAC7NNnf56dkQiZ9bRUIhR9vwQ3j0FMvuUxHhufmC+e7Oxpci4mQ0Yb1lur8/Fhyhl 7OPtsJDmJf9AOJ20R4iBUVJPzELTfewGnfibCSN6WVeLLpzZbOASTL8mv7RV6Kbwh+mZ Lwkwx0whdx7GAqPMqkPLAOPCO7uCoVraKymmE4YNMoo+aOe/6O/oauQ6T5Vai+a9K0ST gI21amA0n+I27y2eHjzOOwLykiymcffFkifnEqzADGkUG/jOgzZGMDw2MEHlyQ0Yi9mG bug0uJuXF+0DFPMo75Z1Fh3djfnYNccSwp5oyS4+aCTnKR8PUPID++p/9Jro8yeHQkSD SMzg== X-Gm-Message-State: AOAM533CIFMlLYrWC8mxQV69bYqDOq7X5AIx08OIwyjNr4sFCYC31OUo ZkfmjuHJCb0QGe9jTecxRUw= X-Google-Smtp-Source: ABdhPJz8XgRWh/DrspKBxOpq2nJ7zjRh2KnIBQpCElACsjTDH6tI9p05DH5yC8t5D444aBcTaGo8rg== X-Received: by 2002:a2e:9784:: with SMTP id y4mr2366447lji.16.1621309276652; Mon, 17 May 2021 20:41:16 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:16 -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 Subject: [PATCH v3 06/14] PCI/P2PDMA: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:01 +0000 Message-Id: <20210518034109.158450-6-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:02 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: 12263475 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 D0EE5C43462 for ; Tue, 18 May 2021 03:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF200611BE for ; Tue, 18 May 2021 03:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242825AbhERDmh (ORCPT ); Mon, 17 May 2021 23:42:37 -0400 Received: from mail-lj1-f178.google.com ([209.85.208.178]:43522 "EHLO mail-lj1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240994AbhERDmg (ORCPT ); Mon, 17 May 2021 23:42:36 -0400 Received: by mail-lj1-f178.google.com with SMTP id w15so9765677ljo.10 for ; Mon, 17 May 2021 20:41:18 -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=XjB3rHV3Gs9lLrvtOrxv7pRKv1N16KnxMCWrz2+cCtE=; b=NBbd+kCrnEMvx8VHOxZ0KFk8YzV1AYOgkaJhSjH4SUjQiF06kLHv/Q1WYfNr6KD8v6 Q1Yt1nhbx56IzfUaY5uXTSXucYFeGyHXRtXoZSzVoETI1bcf/LOFWHmVXEX3KlbQoM/F uT1gQZ6w1I0eYjbheWUwstfnYmCj/dfFK0EJjTqRkaE5hxJxcYhvFGOv3eAU5+erQJAs 8uNWcGo1lI8TWAKVEcE+0QCUvVO327imSAKZzusnbOX1bFoBWH1dlogPeW0Y671oHPmc oxpl2GcWbUDemkkgY934Hfa0OlPrbGOIetXsSOuxKN+j1SOXgvW8wjHTMHQ9oqX6fncN oIHw== X-Gm-Message-State: AOAM530tpetPOnzh9hj7CVhGk3OQpOXe+sGBuxd0sFetTfOfqhIIrFeD LUOCwRwt0QiDEcb+eK/S710= X-Google-Smtp-Source: ABdhPJxpe/XC7QxjGb2CyJjnubIAt+mNpUZwGzlu6CR1lOvtQUVF44rrJ88kui34Efp/yizHoFQEpQ== X-Received: by 2002:a2e:bc23:: with SMTP id b35mr2358933ljf.378.1621309277631; Mon, 17 May 2021 20:41:17 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:17 -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 Subject: [PATCH v3 07/14] PCI/ASPM: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:02 +0000 Message-Id: <20210518034109.158450-7-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:03 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: 12263477 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 62D35C43600 for ; Tue, 18 May 2021 03:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4536B61285 for ; Tue, 18 May 2021 03:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240994AbhERDmi (ORCPT ); Mon, 17 May 2021 23:42:38 -0400 Received: from mail-lf1-f49.google.com ([209.85.167.49]:40773 "EHLO mail-lf1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241281AbhERDmg (ORCPT ); Mon, 17 May 2021 23:42:36 -0400 Received: by mail-lf1-f49.google.com with SMTP id w33so3972565lfu.7 for ; Mon, 17 May 2021 20:41:19 -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=YYexlpupQkJ4g4HrhV8RflzWUH4LyvQnRB/A09302VE=; b=L/JX6gTcE/o4gRQSCSaQsDNp34KPbHRr48hsHKDhSsG8voTRWb3lemFpLy19HAS3zQ 5SESFjp7UVIYGAfQbtoax0R7I9mPIdYcRUcON42zx5ZXNqr2CSmhD9qXnUdou9LWWzEa /psl5FQGrEKuh0yftze7L4z7XOjfNO8UMbJmeGamXssbhZtvpbaP39twPhP6rX4hBPxq +WqKyxx+Q8LX+5+jMpMDp0ttN4hS0jTL47DOktMSa7TKktoxKljvslRRrj+eVx/+BEYF Sixo+IdOV7gZXn3CFniJ04N9N9Sw7o0SMUKGMUulnzX31yuAcI+tIfbzpbmQFxnre3dN HCkg== X-Gm-Message-State: AOAM533GJbHSA2nyWxJLWcDhx1Hc0J7USmuy5Djw3bjOnUg1T/vErXyI t9gle8qiP49q0glHFYqgCDrcaxI9i9Lk0nto X-Google-Smtp-Source: ABdhPJx3yOMyWbiwm6YcdJdBiedqi+HENBN6VuZHYyUoGNacektPXs9qSSn3pHk0HiJn8qx2H6l7dQ== X-Received: by 2002:a05:6512:1326:: with SMTP id x38mr2475489lfu.62.1621309278629; Mon, 17 May 2021 20:41:18 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:18 -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 Subject: [PATCH v3 08/14] PCI: switchtec: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:03 +0000 Message-Id: <20210518034109.158450-8-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:04 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: 12263479 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 8FC42C433ED for ; Tue, 18 May 2021 03:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 729AD61263 for ; Tue, 18 May 2021 03:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344385AbhERDmi (ORCPT ); Mon, 17 May 2021 23:42:38 -0400 Received: from mail-lf1-f47.google.com ([209.85.167.47]:46874 "EHLO mail-lf1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344073AbhERDmi (ORCPT ); Mon, 17 May 2021 23:42:38 -0400 Received: by mail-lf1-f47.google.com with SMTP id i9so11908906lfe.13 for ; Mon, 17 May 2021 20:41:20 -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=uA1RWHjwHfxS7RqMsPnvAHkBLZgV1XkLD2dXTAoz6Eo=; b=QdzwbA7J+7jL2wmKZb009Gg64l7cwarcPCsNuHpsFe948D0f/Bbgs2gnMU3FYcZerz +Nr6TQD/wmLszVu/9TZVr8S4IeeZh5psE+SnjDPU6CQw9/VK+GzBUVLvGHnkqW0D86xJ lZBHggim4xJ3hO39bnDzr6aI0iSLmGl0rI55PTYvZ07AQlu+bnKu4IRwIU+P4W/o1e7b 0W1LIHKVaLh2nHhHA+ldYKx56KNMl22cAb56PUnKM+Ik7SltjfXvq556wufy/HPt1S/G FnvtLOm7A8WrLAAzpyqTjzPDBtvnxR1NZk4Skt56pMS8CIpn+1aKeJoYhY6mUQPZbTl3 Iy8A== X-Gm-Message-State: AOAM533/1SKpX1IWCLrpfs2GnvzLvkufxMZhZY6G3wNnZESsVpc2DRq+ fx45rcMCohy4iso6ttCBw+I= X-Google-Smtp-Source: ABdhPJzFHGyQqyCizXNU0SRBAx+tLKCu8KjtzMw1iBmwxAMWiD2SzqaqTXvxsqWeKxo9N7W6rH5Lzw== X-Received: by 2002:ac2:42ca:: with SMTP id n10mr2514089lfl.330.1621309279756; Mon, 17 May 2021 20:41:19 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:19 -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 Subject: [PATCH v3 09/14] PCI: rpadlpar: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:04 +0000 Message-Id: <20210518034109.158450-9-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:05 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: 12263481 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C10C8C433B4 for ; Tue, 18 May 2021 03:41:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93428611BE for ; Tue, 18 May 2021 03:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346288AbhERDmj (ORCPT ); Mon, 17 May 2021 23:42:39 -0400 Received: from mail-lj1-f171.google.com ([209.85.208.171]:45857 "EHLO mail-lj1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243301AbhERDmj (ORCPT ); Mon, 17 May 2021 23:42:39 -0400 Received: by mail-lj1-f171.google.com with SMTP id v5so9762524ljg.12 for ; Mon, 17 May 2021 20:41:21 -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=Wjg3DIlrANENTm1zkcOPGunwcpnmhITeO03CihxYRc8=; b=BtM9qjv0/cEHAVJOzTVEmZylYv/oYDiAH65kCg71hTt6VTk9par2/JuVAl2CBrZcqi RPcDxOCHEdsGX4c9l+KwoC3kotxXvDp1Ng/EqKNw3SZcKqxXAI4jByWpwaCL0b3avkCF 95tI6nBn907Fd5SmoxEesDre2IQUGoFVRaDthCeATrMk+ILqkklrzBg16FpSW4x0+DIx MkWymS29vU1hA30G/HVK+XDRLvxYSbpADzWLIMEv76SFlGwozFQGtQ+6RGCy9iE33a8n KMZNgNud970FuiVobz5frC4/31RdE86elPUoqllDsw8QQw0XvXbj3Zll1L2c3DR5ijgR MCIQ== X-Gm-Message-State: AOAM532bQ6GvbuyZUKJx5xZrEmZR9/O26pB9ZYrrUi7nOqYfzQE9trgt ZtNxgak6yTidcSuKVLBrVMY= X-Google-Smtp-Source: ABdhPJz4rV3Dp89mOuLSi0uuAmmbwXMQq8KL1Gv9VuMb0QMRiaA1fw4PMXFPki52hZ79du8RHdjd+w== X-Received: by 2002:a2e:580d:: with SMTP id m13mr2179947ljb.31.1621309280759; Mon, 17 May 2021 20:41:20 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:20 -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 Subject: [PATCH v3 10/14] PCI: hotplug: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:05 +0000 Message-Id: <20210518034109.158450-10-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:06 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: 12263483 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 78330C43460 for ; Tue, 18 May 2021 03:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 522F0611CC for ; Tue, 18 May 2021 03:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344971AbhERDmk (ORCPT ); Mon, 17 May 2021 23:42:40 -0400 Received: from mail-lf1-f46.google.com ([209.85.167.46]:34710 "EHLO mail-lf1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343901AbhERDmk (ORCPT ); Mon, 17 May 2021 23:42:40 -0400 Received: by mail-lf1-f46.google.com with SMTP id z13so11959026lft.1 for ; Mon, 17 May 2021 20:41: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:in-reply-to :references:mime-version:content-transfer-encoding; bh=RYiVudpZEsIvY1SAQVRkZoG3SY2AtLnP2gPfuroRoOM=; b=Ryrcsh3vyIjxZ3xlL8CRnEEDFRekvJpdM4wlJQKiZJ0aYsBeGC1SuJnhgAooyjaUuG bWjozE2eow8U11/GlSBaslBk3E89W6MhTxyn/Yj4OkfcShNIM1x29TbMvnow5ABd4vwh NzzHZNyurHzquRvJ9hJoaXkBn+c8brIxxd+7poRxaG9nT9YAwGJI9JyInRdwfYT2RJRb bFp+x7R824FZuOY/o8LHPz9mwvwpL+Tu6TxD3KzfbzHWoW6HelrkZ4fQROBfPz7dCrwD YVceC1y5XiGkufy/6PB+VdIjSQKO962QPcl+IuVo2wFGiLZdE4G0HGJlgzKNJvoMzGpJ DEfA== X-Gm-Message-State: AOAM530Adi5dnnpWtY06j1mmwR0pc2NFR+eXg5+Zfyb3wdg+nGsG2iMQ +ev70EtiGqvnUDNQxpCj60Y= X-Google-Smtp-Source: ABdhPJyr0If6/isZrT2WhjemvEmfJqibs1APcEz/Lxtw2XWUE9Ibs5RmL1HQL7EbOCWQpt/UyHLmpg== X-Received: by 2002:a19:354:: with SMTP id 81mr2569583lfd.174.1621309281745; Mon, 17 May 2021 20:41:21 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:21 -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 Subject: [PATCH v3 11/14] PCI: shpchp: Use sysfs_emit() and sysfs_emit_at() in "show" functions Date: Tue, 18 May 2021 03:41:06 +0000 Message-Id: <20210518034109.158450-11-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:07 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: 12263485 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 22CCBC433B4 for ; Tue, 18 May 2021 03:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0622061263 for ; Tue, 18 May 2021 03:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344073AbhERDml (ORCPT ); Mon, 17 May 2021 23:42:41 -0400 Received: from mail-lf1-f47.google.com ([209.85.167.47]:45717 "EHLO mail-lf1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243301AbhERDml (ORCPT ); Mon, 17 May 2021 23:42:41 -0400 Received: by mail-lf1-f47.google.com with SMTP id j10so11904199lfb.12 for ; Mon, 17 May 2021 20:41:23 -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=bFxWTz4RawfMY7EO22L+kcfgeoSi7PKwliMf+ys+Dig=; b=ZYp4jF4D3JlpEWi70yXI7ncnd9gxVdeiPMleGGt78fiXnQQIwp5AeEJ9ETjTIc7OCP bMTElfGdmpBk+b8KvmOumnTT2mqINMIBxDlAM4XFKM4sePLMDuA0C4w41NHPX6ZnPg0G BVupcl5gUZ0Gk3ObXttpJR3quM3JWd6bxFdUbxEJgqcxbzs2cCPVdD2/q1Sb7S3YJELl yh7IwC0nNBdgd+mGHy53dtYQ+ia3qsnuS2E8ZaDMEAoBnG2asKtEmhHLkew//EnXY4d6 IVd95I+R00g5d+RnTTsCUYc3Dr0T7VwtfAUdIjQqFAP07MnyPGHPp5+gh7yaOcZpziNk KntA== X-Gm-Message-State: AOAM5329/OpLQJ2EtdsNsZaCZcYVscCfmbs59eV9cW7MCKCf4Wk1gZ++ 2MA1Mf/1XMAdbYevKjvLJjA= X-Google-Smtp-Source: ABdhPJxH/0FQMxEtSAUyp7JXQx01kDi7SBRLSXhr9jMXiJ+fIHyzqgZJ2623S7E0PKu0HQo9OTe9jg== X-Received: by 2002:a05:6512:3185:: with SMTP id i5mr2668771lfe.67.1621309282742; Mon, 17 May 2021 20:41:22 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:22 -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 Subject: [PATCH v3 12/14] PCI: Fix trailing newline handling of resource_alignment_param Date: Tue, 18 May 2021 03:41:07 +0000 Message-Id: <20210518034109.158450-12-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:08 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: 12263487 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 B7B52C43461 for ; Tue, 18 May 2021 03:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9491C611CC for ; Tue, 18 May 2021 03:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345772AbhERDmm (ORCPT ); Mon, 17 May 2021 23:42:42 -0400 Received: from mail-lf1-f52.google.com ([209.85.167.52]:39838 "EHLO mail-lf1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241281AbhERDmm (ORCPT ); Mon, 17 May 2021 23:42:42 -0400 Received: by mail-lf1-f52.google.com with SMTP id q7so10604720lfr.6 for ; Mon, 17 May 2021 20:41:24 -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=7ce2Mqrx6CrD0pUNAC8XjuNA5uU1leumU5uK08mhq7I=; b=QojvIaEMOFK+fFLlQjtdNGCE/goOimkw4CLwFJH3RJa7h3Azfk8GGn8xO7DwWVBXWH B5zv5uOKwPdhRbJLsd2Ge3RVjPP8XHoAZljKpAKykTt/u8J2zBXbqnf00yk/78rSvv5H R6YGhry5tff1rgYhQfAa+PM0Wc+DOplkOIy3YNBtt7IwPB9H0hQQEXo1UnJYO99bvkuo 1mBriCY3Jy8ha88YIn8yQ7YNBi0wniwCSKCD7MJenc7Al9WlM5kJcKiGmneSsZxFHl9p Bbw7/wGjOU9Civs+iPq6chIObPYydWHXMb9Dulbf21oHC7V4Kqeyig2UOEGPc1nepFmc VDKg== X-Gm-Message-State: AOAM533CASSq8U+qFUNFAswyn37zrHdgjUBapucsYjbBXZpoakwL6PtQ 39RlgwRmL3JH1IdMBF0RXW4= X-Google-Smtp-Source: ABdhPJy/QYjL/LDei5Kj5TxUOO80kC/GTJbf8Q8FI2H1694n1M0YMXpyAk+rvacTyzlvf2uA/6MoZw== X-Received: by 2002:a05:6512:388f:: with SMTP id n15mr2744448lft.280.1621309283739; Mon, 17 May 2021 20:41:23 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:23 -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 Subject: [PATCH v3 13/14] PCI/sysfs: Add missing trailing newline to devspec_show() Date: Tue, 18 May 2021 03:41:08 +0000 Message-Id: <20210518034109.158450-13-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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 Tue May 18 03:41:09 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: 12263489 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.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 50850C433B4 for ; Tue, 18 May 2021 03:41:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3415C6109E for ; Tue, 18 May 2021 03:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346289AbhERDmn (ORCPT ); Mon, 17 May 2021 23:42:43 -0400 Received: from mail-lj1-f181.google.com ([209.85.208.181]:33549 "EHLO mail-lj1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243059AbhERDmm (ORCPT ); Mon, 17 May 2021 23:42:42 -0400 Received: by mail-lj1-f181.google.com with SMTP id o8so9845822ljp.0 for ; Mon, 17 May 2021 20:41:25 -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=1spWpjRWutJF00hdbYEaMffPbCAUG6R0mq8npz/96kI=; b=fGhD77hE3zJP7hV0Geq6eRApEYSSD96LO98qrvJq+8oc8wgGjoTJ+dlFany18tTeKo SFtABYAc+juiXxS1oWlveZk1I28jb6mvRii0IXefpWbm3ize31csJTLKOCnvLKVOd8Td SUTE/F4gSKUFkWAWXDZtfFIwyYk8qRDPfW4bF58mpV5FB+cJMIRHiik9s/Y0XbSTP5qQ 9G+fhBX6+iDoU1DMsuCAY7e6y7y60B4tEaIVqCc+4t8k9rfjD4ZatHyVTlRG6w5OSs7U jktjDntr5ZNmO/BDxVLdqWkuaz8d9vPXthBO/JKJWgOXbHZfrWuOCFHgznWLJ38cWi9k 08+w== X-Gm-Message-State: AOAM530Dz91duFx+YbU6nkXeYj7PAcvuac+nzzpY2iV3BBZ5yvHOS9TM D4RohELfDUOeIRTmwAWRMIU= X-Google-Smtp-Source: ABdhPJyrkgkyMrT192aKsBz4oMBf4c0Uhp47zRxsn2+8r17eCcuJjO48OxADQ9++6BEpOfEcMaBiSQ== X-Received: by 2002:a05:651c:119c:: with SMTP id w28mr2308078ljo.164.1621309284703; Mon, 17 May 2021 20:41:24 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id j23sm419112lfm.276.2021.05.17.20.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 20:41:24 -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 Subject: [PATCH v3 14/14] PCI/sysfs: Only show value when driver_override is not NULL Date: Tue, 18 May 2021 03:41:09 +0000 Message-Id: <20210518034109.158450-14-kw@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518034109.158450-1-kw@linux.com> References: <20210518034109.158450-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 Reviewed-by: Logan Gunthorpe --- Changes in v2: None. Changes in v3: Added Logan Gunthorpe's "Reviewed-by". 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; }