diff mbox series

[v5,4/9] PCI: endpoint: Warn and return if EPC is started/stopped multiple times

Message ID 20230601145718.12204-5-manivannan.sadhasivam@linaro.org (mailing list archive)
State Superseded
Headers show
Series Add support for MHI Endpoint function driver | expand

Commit Message

Manivannan Sadhasivam June 1, 2023, 2:57 p.m. UTC
When the EPC is started or stopped multiple times from configfs, just emit
a once time warning and return. There is no need to call the EPC start/stop
functions in those cases.

Reviewed-by: Kishon Vijay Abraham I <kishon@kernel.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/pci/endpoint/pci-ep-cfs.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Damien Le Moal June 1, 2023, 11:18 p.m. UTC | #1
On 6/1/23 23:57, Manivannan Sadhasivam wrote:
> When the EPC is started or stopped multiple times from configfs, just emit
> a once time warning and return. There is no need to call the EPC start/stop
> functions in those cases.
> 
> Reviewed-by: Kishon Vijay Abraham I <kishon@kernel.org>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/pci/endpoint/pci-ep-cfs.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
> index 4b8ac0ac84d5..62c8e09c59f4 100644
> --- a/drivers/pci/endpoint/pci-ep-cfs.c
> +++ b/drivers/pci/endpoint/pci-ep-cfs.c
> @@ -178,6 +178,9 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page,
>  	if (kstrtobool(page, &start) < 0)
>  		return -EINVAL;
>  
> +	if (WARN_ON_ONCE(start == epc_group->start))
> +		return 0;

WARN will dump a backtrace which is fairly scary for the user. This case is
simply a bad user manipulation of the device, so why not simply add a pr_err()
(optional) and return -EALREADY ?

> +
>  	if (!start) {
>  		pci_epc_stop(epc);
>  		epc_group->start = 0;
Manivannan Sadhasivam June 2, 2023, 3:27 a.m. UTC | #2
On Fri, Jun 02, 2023 at 08:18:58AM +0900, Damien Le Moal wrote:
> On 6/1/23 23:57, Manivannan Sadhasivam wrote:
> > When the EPC is started or stopped multiple times from configfs, just emit
> > a once time warning and return. There is no need to call the EPC start/stop
> > functions in those cases.
> > 
> > Reviewed-by: Kishon Vijay Abraham I <kishon@kernel.org>
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  drivers/pci/endpoint/pci-ep-cfs.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
> > index 4b8ac0ac84d5..62c8e09c59f4 100644
> > --- a/drivers/pci/endpoint/pci-ep-cfs.c
> > +++ b/drivers/pci/endpoint/pci-ep-cfs.c
> > @@ -178,6 +178,9 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page,
> >  	if (kstrtobool(page, &start) < 0)
> >  		return -EINVAL;
> >  
> > +	if (WARN_ON_ONCE(start == epc_group->start))
> > +		return 0;
> 
> WARN will dump a backtrace which is fairly scary for the user. This case is
> simply a bad user manipulation of the device, so why not simply add a pr_err()
> (optional) and return -EALREADY ?
> 

There EPF core uses WARN_ON_ONCE in other similar places, so thought of sticking
to that pattern. But I agree, WARN_ON_ONCE is not strictly required here. Will
add a error log and return the appropriate error no.

Moreover, will push a patch later to change other instances as well.

- Mani

> > +
> >  	if (!start) {
> >  		pci_epc_stop(epc);
> >  		epc_group->start = 0;
> 
> -- 
> Damien Le Moal
> Western Digital Research
>
diff mbox series

Patch

diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
index 4b8ac0ac84d5..62c8e09c59f4 100644
--- a/drivers/pci/endpoint/pci-ep-cfs.c
+++ b/drivers/pci/endpoint/pci-ep-cfs.c
@@ -178,6 +178,9 @@  static ssize_t pci_epc_start_store(struct config_item *item, const char *page,
 	if (kstrtobool(page, &start) < 0)
 		return -EINVAL;
 
+	if (WARN_ON_ONCE(start == epc_group->start))
+		return 0;
+
 	if (!start) {
 		pci_epc_stop(epc);
 		epc_group->start = 0;