linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions
@ 2021-09-01  5:09 Kunihiko Hayashi
  2021-09-16 11:30 ` Kunihiko Hayashi
  2021-09-30 11:05 ` Lorenzo Pieralisi
  0 siblings, 2 replies; 4+ messages in thread
From: Kunihiko Hayashi @ 2021-09-01  5:09 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi, Kishon Vijay Abraham I,
	Krzysztof Wilczyński
  Cc: linux-pci, linux-kernel, Kunihiko Hayashi

Convert sprintf() in sysfs "show" functions to sysfs_emit() in order to
check for buffer overruns in sysfs outputs.

Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Reviewed-by: Krzysztof Wilczyński <kw@linux.com>
---
Changes since v1:
- Add Reviewed-by line

---
drivers/pci/endpoint/functions/pci-epf-ntb.c |  4 ++--
 drivers/pci/endpoint/pci-ep-cfs.c            | 13 ++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c
index 8b47561..99266f05 100644
--- a/drivers/pci/endpoint/functions/pci-epf-ntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c
@@ -1937,7 +1937,7 @@ static ssize_t epf_ntb_##_name##_show(struct config_item *item,		\
 	struct config_group *group = to_config_group(item);		\
 	struct epf_ntb *ntb = to_epf_ntb(group);			\
 									\
-	return sprintf(page, "%d\n", ntb->_name);			\
+	return sysfs_emit(page, "%d\n", ntb->_name);			\
 }
 
 #define EPF_NTB_W(_name)						\
@@ -1968,7 +1968,7 @@ static ssize_t epf_ntb_##_name##_show(struct config_item *item,		\
 									\
 	sscanf(#_name, "mw%d", &win_no);				\
 									\
-	return sprintf(page, "%lld\n", ntb->mws_size[win_no - 1]);	\
+	return sysfs_emit(page, "%lld\n", ntb->mws_size[win_no - 1]);	\
 }
 
 #define EPF_NTB_MW_W(_name)						\
diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
index 9999118..5a0394a 100644
--- a/drivers/pci/endpoint/pci-ep-cfs.c
+++ b/drivers/pci/endpoint/pci-ep-cfs.c
@@ -198,8 +198,7 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page,
 
 static ssize_t pci_epc_start_show(struct config_item *item, char *page)
 {
-	return sprintf(page, "%d\n",
-		       to_pci_epc_group(item)->start);
+	return sysfs_emit(page, "%d\n", to_pci_epc_group(item)->start);
 }
 
 CONFIGFS_ATTR(pci_epc_, start);
@@ -321,7 +320,7 @@ static ssize_t pci_epf_##_name##_show(struct config_item *item,	char *page)    \
 	struct pci_epf *epf = to_pci_epf_group(item)->epf;		       \
 	if (WARN_ON_ONCE(!epf->header))					       \
 		return -EINVAL;						       \
-	return sprintf(page, "0x%04x\n", epf->header->_name);		       \
+	return sysfs_emit(page, "0x%04x\n", epf->header->_name);	       \
 }
 
 #define PCI_EPF_HEADER_W_u32(_name)					       \
@@ -390,8 +389,8 @@ static ssize_t pci_epf_msi_interrupts_store(struct config_item *item,
 static ssize_t pci_epf_msi_interrupts_show(struct config_item *item,
 					   char *page)
 {
-	return sprintf(page, "%d\n",
-		       to_pci_epf_group(item)->epf->msi_interrupts);
+	return sysfs_emit(page, "%d\n",
+			  to_pci_epf_group(item)->epf->msi_interrupts);
 }
 
 static ssize_t pci_epf_msix_interrupts_store(struct config_item *item,
@@ -412,8 +411,8 @@ static ssize_t pci_epf_msix_interrupts_store(struct config_item *item,
 static ssize_t pci_epf_msix_interrupts_show(struct config_item *item,
 					    char *page)
 {
-	return sprintf(page, "%d\n",
-		       to_pci_epf_group(item)->epf->msix_interrupts);
+	return sysfs_emit(page, "%d\n",
+			  to_pci_epf_group(item)->epf->msix_interrupts);
 }
 
 PCI_EPF_HEADER_R(vendorid)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions
  2021-09-01  5:09 [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions Kunihiko Hayashi
@ 2021-09-16 11:30 ` Kunihiko Hayashi
  2021-09-16 22:43   ` Krzysztof Wilczyński
  2021-09-30 11:05 ` Lorenzo Pieralisi
  1 sibling, 1 reply; 4+ messages in thread
From: Kunihiko Hayashi @ 2021-09-16 11:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi, Kishon Vijay Abraham I,
	Krzysztof Wilczyński
  Cc: linux-pci, linux-kernel

Gentle ping, are there any comments?

Thank you,

On 2021/09/01 14:09, Kunihiko Hayashi wrote:
> Convert sprintf() in sysfs "show" functions to sysfs_emit() in order to
> check for buffer overruns in sysfs outputs.
> 
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> Reviewed-by: Krzysztof Wilczyński <kw@linux.com>
> ---
> Changes since v1:
> - Add Reviewed-by line
> 
> ---
> drivers/pci/endpoint/functions/pci-epf-ntb.c |  4 ++--
>   drivers/pci/endpoint/pci-ep-cfs.c            | 13 ++++++-------
>   2 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c
> index 8b47561..99266f05 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c
> @@ -1937,7 +1937,7 @@ static ssize_t epf_ntb_##_name##_show(struct config_item *item,		\
>   	struct config_group *group = to_config_group(item);		\
>   	struct epf_ntb *ntb = to_epf_ntb(group);			\
>   									\
> -	return sprintf(page, "%d\n", ntb->_name);			\
> +	return sysfs_emit(page, "%d\n", ntb->_name);			\
>   }
>   
>   #define EPF_NTB_W(_name)						\
> @@ -1968,7 +1968,7 @@ static ssize_t epf_ntb_##_name##_show(struct config_item *item,		\
>   									\
>   	sscanf(#_name, "mw%d", &win_no);				\
>   									\
> -	return sprintf(page, "%lld\n", ntb->mws_size[win_no - 1]);	\
> +	return sysfs_emit(page, "%lld\n", ntb->mws_size[win_no - 1]);	\
>   }
>   
>   #define EPF_NTB_MW_W(_name)						\
> diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
> index 9999118..5a0394a 100644
> --- a/drivers/pci/endpoint/pci-ep-cfs.c
> +++ b/drivers/pci/endpoint/pci-ep-cfs.c
> @@ -198,8 +198,7 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page,
>   
>   static ssize_t pci_epc_start_show(struct config_item *item, char *page)
>   {
> -	return sprintf(page, "%d\n",
> -		       to_pci_epc_group(item)->start);
> +	return sysfs_emit(page, "%d\n", to_pci_epc_group(item)->start);
>   }
>   
>   CONFIGFS_ATTR(pci_epc_, start);
> @@ -321,7 +320,7 @@ static ssize_t pci_epf_##_name##_show(struct config_item *item,	char *page)    \
>   	struct pci_epf *epf = to_pci_epf_group(item)->epf;		       \
>   	if (WARN_ON_ONCE(!epf->header))					       \
>   		return -EINVAL;						       \
> -	return sprintf(page, "0x%04x\n", epf->header->_name);		       \
> +	return sysfs_emit(page, "0x%04x\n", epf->header->_name);	       \
>   }
>   
>   #define PCI_EPF_HEADER_W_u32(_name)					       \
> @@ -390,8 +389,8 @@ static ssize_t pci_epf_msi_interrupts_store(struct config_item *item,
>   static ssize_t pci_epf_msi_interrupts_show(struct config_item *item,
>   					   char *page)
>   {
> -	return sprintf(page, "%d\n",
> -		       to_pci_epf_group(item)->epf->msi_interrupts);
> +	return sysfs_emit(page, "%d\n",
> +			  to_pci_epf_group(item)->epf->msi_interrupts);
>   }
>   
>   static ssize_t pci_epf_msix_interrupts_store(struct config_item *item,
> @@ -412,8 +411,8 @@ static ssize_t pci_epf_msix_interrupts_store(struct config_item *item,
>   static ssize_t pci_epf_msix_interrupts_show(struct config_item *item,
>   					    char *page)
>   {
> -	return sprintf(page, "%d\n",
> -		       to_pci_epf_group(item)->epf->msix_interrupts);
> +	return sysfs_emit(page, "%d\n",
> +			  to_pci_epf_group(item)->epf->msix_interrupts);
>   }
>   
>   PCI_EPF_HEADER_R(vendorid)
> 

-- 
---
Best Regards
Kunihiko Hayashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions
  2021-09-16 11:30 ` Kunihiko Hayashi
@ 2021-09-16 22:43   ` Krzysztof Wilczyński
  0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Wilczyński @ 2021-09-16 22:43 UTC (permalink / raw)
  To: Kunihiko Hayashi
  Cc: Bjorn Helgaas, Lorenzo Pieralisi, Kishon Vijay Abraham I,
	linux-pci, linux-kernel

Hayashi-san,

Thank you for sending this as separate patch.

> Gentle ping, are there any comments?

I am sure Bjorn or Lorenzo will get to this patch soon, it's still marked
as "New" in patchwork, as per:
  https://patchwork.kernel.org/project/linux-pci/patch/1630472957-26857-1-git-send-email-hayashi.kunihiko@socionext.com/

My "Reviewed-by" still applies, of course.

[...]
> > Convert sprintf() in sysfs "show" functions to sysfs_emit() in order to
> > check for buffer overruns in sysfs outputs.

As Bjorn, or someone else might ask, you could add a short note about this
being configfs, rather than sysfs, and that sysfs_emit() will still work.

Something as per what I said while commenting on the previous patch:
  https://lore.kernel.org/all/20210719034313.GA274232@rocinante/

	Krzysztof

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions
  2021-09-01  5:09 [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions Kunihiko Hayashi
  2021-09-16 11:30 ` Kunihiko Hayashi
@ 2021-09-30 11:05 ` Lorenzo Pieralisi
  1 sibling, 0 replies; 4+ messages in thread
From: Lorenzo Pieralisi @ 2021-09-30 11:05 UTC (permalink / raw)
  To: Bjorn Helgaas, Kunihiko Hayashi, Kishon Vijay Abraham I,
	Krzysztof Wilczyński
  Cc: Lorenzo Pieralisi, linux-kernel, linux-pci

On Wed, 1 Sep 2021 14:09:17 +0900, Kunihiko Hayashi wrote:
> Convert sprintf() in sysfs "show" functions to sysfs_emit() in order to
> check for buffer overruns in sysfs outputs.
> 
> 

Applied to pci/endpoint, thanks!

[1/1] PCI: endpoint: Use sysfs_emit() in "show" functions
      https://git.kernel.org/lpieralisi/pci/c/a2258831d1

Thanks,
Lorenzo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-30 11:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  5:09 [PATCH v2] PCI: endpoint: Use sysfs_emit() in "show" functions Kunihiko Hayashi
2021-09-16 11:30 ` Kunihiko Hayashi
2021-09-16 22:43   ` Krzysztof Wilczyński
2021-09-30 11:05 ` Lorenzo Pieralisi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).