public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling
@ 2018-08-02  8:42 Dan Carpenter
  2018-08-08 23:13 ` Sudeep Dutt
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-08-02  8:42 UTC (permalink / raw)
  To: Sudeep Dutt
  Cc: Ashutosh Dixit, Arnd Bergmann, Greg Kroah-Hartman, Al Viro,
	Gustavo A. R. Silva, linux-kernel, kernel-janitors

There are only 2 callers of scif_get_new_port() and both appear to get
the error handling wrong.  Both treat zero returns as error, but it
actually returns negative error codes and >= 0 on success.

Fixes: e9089f43c9a7 ("misc: mic: SCIF open close bind and listen APIs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I have not tested this patch.  Please review carefully.

diff --git a/drivers/misc/mic/scif/scif_api.c b/drivers/misc/mic/scif/scif_api.c
index 463f06d0b4ef..8dd0ccedeb94 100644
--- a/drivers/misc/mic/scif/scif_api.c
+++ b/drivers/misc/mic/scif/scif_api.c
@@ -371,11 +371,10 @@ int scif_bind(scif_epd_t epd, u16 pn)
 			goto scif_bind_exit;
 		}
 	} else {
-		pn = scif_get_new_port();
-		if (!pn) {
-			ret = -ENOSPC;
+		ret = scif_get_new_port();
+		if (ret < 0)
 			goto scif_bind_exit;
-		}
+		pn = ret;
 	}
 
 	ep->state = SCIFEP_BOUND;
@@ -649,13 +648,12 @@ int __scif_connect(scif_epd_t epd, struct scif_port_id *dst, bool non_block)
 			err = -EISCONN;
 		break;
 	case SCIFEP_UNBOUND:
-		ep->port.port = scif_get_new_port();
-		if (!ep->port.port) {
-			err = -ENOSPC;
-		} else {
-			ep->port.node = scif_info.nodeid;
-			ep->conn_async_state = ASYNC_CONN_IDLE;
-		}
+		err = scif_get_new_port();
+		if (err < 0)
+			break;
+		ep->port.port = err;
+		ep->port.node = scif_info.nodeid;
+		ep->conn_async_state = ASYNC_CONN_IDLE;
 		/* Fall through */
 	case SCIFEP_BOUND:
 		/*

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

* Re: [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling
  2018-08-02  8:42 [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling Dan Carpenter
@ 2018-08-08 23:13 ` Sudeep Dutt
  0 siblings, 0 replies; 2+ messages in thread
From: Sudeep Dutt @ 2018-08-08 23:13 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sudeep Dutt, Dixit, Ashutosh, Arnd Bergmann, Greg Kroah-Hartman,
	Al Viro, Gustavo A. R. Silva, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org

On Thu, 2018-08-02 at 01:42 -0700, Dan Carpenter wrote:
> There are only 2 callers of scif_get_new_port() and both appear to get
> the error handling wrong.  Both treat zero returns as error, but it
> actually returns negative error codes and >= 0 on success.
> 
> Fixes: e9089f43c9a7 ("misc: mic: SCIF open close bind and listen APIs")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> I have not tested this patch.  Please review carefully.

Thanks for the patch Dan.

Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com>

> 
> diff --git a/drivers/misc/mic/scif/scif_api.c b/drivers/misc/mic/scif/scif_api.c
> index 463f06d0b4ef..8dd0ccedeb94 100644
> --- a/drivers/misc/mic/scif/scif_api.c
> +++ b/drivers/misc/mic/scif/scif_api.c
> @@ -371,11 +371,10 @@ int scif_bind(scif_epd_t epd, u16 pn)
>  			goto scif_bind_exit;
>  		}
>  	} else {
> -		pn = scif_get_new_port();
> -		if (!pn) {
> -			ret = -ENOSPC;
> +		ret = scif_get_new_port();
> +		if (ret < 0)
>  			goto scif_bind_exit;
> -		}
> +		pn = ret;
>  	}
>  
>  	ep->state = SCIFEP_BOUND;
> @@ -649,13 +648,12 @@ int __scif_connect(scif_epd_t epd, struct scif_port_id *dst, bool non_block)
>  			err = -EISCONN;
>  		break;
>  	case SCIFEP_UNBOUND:
> -		ep->port.port = scif_get_new_port();
> -		if (!ep->port.port) {
> -			err = -ENOSPC;
> -		} else {
> -			ep->port.node = scif_info.nodeid;
> -			ep->conn_async_state = ASYNC_CONN_IDLE;
> -		}
> +		err = scif_get_new_port();
> +		if (err < 0)
> +			break;
> +		ep->port.port = err;
> +		ep->port.node = scif_info.nodeid;
> +		ep->conn_async_state = ASYNC_CONN_IDLE;
>  		/* Fall through */
>  	case SCIFEP_BOUND:
>  		/*



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

end of thread, other threads:[~2018-08-08 23:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-02  8:42 [PATCH] misc: mic: SCIF Fix scif_get_new_port() error handling Dan Carpenter
2018-08-08 23:13 ` Sudeep Dutt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox