From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ursula Braun Subject: Re: [PATCH net-next] net/smc: cast sizeof to int for comparison Date: Mon, 17 Sep 2018 10:49:43 +0200 Message-ID: <554a145a-d59d-9033-1702-4987a9c4bc94@linux.ibm.com> References: <20180915100036.20100-1-yuehaibing@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org To: YueHaibing Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47704 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727204AbeIQOQP (ORCPT ); Mon, 17 Sep 2018 10:16:15 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8H8iMOq003455 for ; Mon, 17 Sep 2018 04:49:49 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mj7q4bd4p-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Sep 2018 04:49:49 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Sep 2018 09:49:46 +0100 In-Reply-To: <20180915100036.20100-1-yuehaibing@huawei.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 09/15/2018 12:00 PM, YueHaibing wrote: > Comparing an int to a size, which is unsigned, causes the int to become > unsigned, giving the wrong result. kernel_sendmsg can return a negative > error code. > Thanks for reporting this issue! > Signed-off-by: YueHaibing > --- > net/smc/smc_clc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c > index 83aba9a..fd0f5ce 100644 > --- a/net/smc/smc_clc.c > +++ b/net/smc/smc_clc.c > @@ -446,7 +446,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type, > vec[i++].iov_len = sizeof(trl); > /* due to the few bytes needed for clc-handshake this cannot block */ > len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen); > - if (len < sizeof(pclc)) { > + if (len < (int)sizeof(pclc)) { > if (len >= 0) { > reason_code = -ENETUNREACH; > smc->sk.sk_err = -reason_code; > Your fix helps, but I would like to follow the hint of Andreas Schwab, and split the return value check like this: --- net/smc/smc_clc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) --- a/net/smc/smc_clc.c +++ b/net/smc/smc_clc.c @@ -446,14 +446,12 @@ int smc_clc_send_proposal(struct smc_soc vec[i++].iov_len = sizeof(trl); /* due to the few bytes needed for clc-handshake this cannot block */ len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen); - if (len < sizeof(pclc)) { - if (len >= 0) { - reason_code = -ENETUNREACH; - smc->sk.sk_err = -reason_code; - } else { - smc->sk.sk_err = smc->clcsock->sk->sk_err; - reason_code = -smc->sk.sk_err; - } + if (len < 0) { + smc->sk.sk_err = smc->clcsock->sk->sk_err; + reason_code = -smc->sk.sk_err; + } else if (len < (int)sizeof(pclc)) { + reason_code = -ENETUNREACH; + smc->sk.sk_err = -reason_code; } return reason_code; Agreed? Regards, Ursula