From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-cys01nam02on0106.outbound.protection.outlook.com ([104.47.37.106]:54352 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730084AbeIBRbi (ORCPT ); Sun, 2 Sep 2018 13:31:38 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Dan Carpenter , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.4 01/47] misc: mic: SCIF Fix scif_get_new_port() error handling Date: Sun, 2 Sep 2018 13:15:39 +0000 Message-ID: <20180902131533.184092-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Dan Carpenter [ Upstream commit a39284ae9d2ad09975c8ae33f1bd0f05fbfbf6ee ] 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 >=3D 0 on success. Fixes: e9089f43c9a7 ("misc: mic: SCIF open close bind and listen APIs") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/mic/scif/scif_api.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/misc/mic/scif/scif_api.c b/drivers/misc/mic/scif/scif_= api.c index ddc9e4b08b5c..56efa9d18a9a 100644 --- a/drivers/misc/mic/scif/scif_api.c +++ b/drivers/misc/mic/scif/scif_api.c @@ -370,11 +370,10 @@ int scif_bind(scif_epd_t epd, u16 pn) goto scif_bind_exit; } } else { - pn =3D scif_get_new_port(); - if (!pn) { - ret =3D -ENOSPC; + ret =3D scif_get_new_port(); + if (ret < 0) goto scif_bind_exit; - } + pn =3D ret; } =20 ep->state =3D SCIFEP_BOUND; @@ -648,13 +647,12 @@ int __scif_connect(scif_epd_t epd, struct scif_port_i= d *dst, bool non_block) err =3D -EISCONN; break; case SCIFEP_UNBOUND: - ep->port.port =3D scif_get_new_port(); - if (!ep->port.port) { - err =3D -ENOSPC; - } else { - ep->port.node =3D scif_info.nodeid; - ep->conn_async_state =3D ASYNC_CONN_IDLE; - } + err =3D scif_get_new_port(); + if (err < 0) + break; + ep->port.port =3D err; + ep->port.node =3D scif_info.nodeid; + ep->conn_async_state =3D ASYNC_CONN_IDLE; /* Fall through */ case SCIFEP_BOUND: /* --=20 2.17.1