Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3135243rdg; Tue, 17 Oct 2023 05:56:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkwm6HpjxsXEYUQjfpXtV0IzNEVx1mZo+w7t/eaK9NLAOMSe6Kwd8nFX5iJs/uI08c002g X-Received: by 2002:a05:6a20:841e:b0:17a:e2b9:77e0 with SMTP id c30-20020a056a20841e00b0017ae2b977e0mr3139523pzd.7.1697547381854; Tue, 17 Oct 2023 05:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697547381; cv=none; d=google.com; s=arc-20160816; b=mdhGZcp1xzcSwMNSpGrd/2ZjTdlYv8B90Ouan+e2MHEd7AOTqMhvjMf2FybYOfjg3j 1J7Yir3Vpi0gSAA7mqWXfTl0OejdfsSRZN+XZhWIlGUnwtTriLF/9vYoERQikSHvNeKu GWo5prl0Q8B0v9D9Jze5AsdqCfqDl7Y0bsQjMZSItXjolyhQ1G0llVv3g1PGcZbSfXKB acTYI2e8duc8zSWpFOMGz1nF6jo4p2m09wWr2g/Yi2TA7n+yU2mTe1SR8R9ALSLUf+Ov 32BSxAoALz2E8PCDTSLS1P335IkuKzBJ6XdFBHJsC7Zl1B/P7JyQC53RtsvtM3LrmSPP vEkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mtHg0IwRDCQ2l/8xePRzo42XR+AT1NpbKMamJOJQMvM=; fh=KWvyQxL3Ff+3WPSMjlYu+P4255AmcMULAsFol6M1vNI=; b=XlIiPeXGB9rR7JMqAK8dPjO0PPcxLO1UxszTkUyn32m1zj7OCiry4ioZ9Np48AN2Mu KVDJ+fEUuoRIYP7yDNeUmk+rJ6Gl5Rdq14AKQsMFe9YTb5ilTYbsuKeGI7RZVtQ02I15 RDlO20LW7ScJ7Etc7Ju1Vm4QB4zU9MaLTJ0Sa9qFgWvCkztcz2PdpRr9dLZDN1VlsvP5 zILh1aFcukYqe8qKYXXExidmZ3bKEnmop+ixJtgrm+KJm0hjgWy1v4D3uDt33tAcvrkG mGa9YzDFqTbr8caJK4Q3YCp4v6eJktacbXzVwA/Wxk9JzKH+/LQd4ICwQij1hrq8mSuk HQBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w186-20020a6382c3000000b005852a35aff4si1773804pgd.227.2023.10.17.05.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B2EF0802911D; Tue, 17 Oct 2023 05:56:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343729AbjJQM4F (ORCPT + 99 others); Tue, 17 Oct 2023 08:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234486AbjJQMz6 (ORCPT ); Tue, 17 Oct 2023 08:55:58 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7134F101; Tue, 17 Oct 2023 05:55:56 -0700 (PDT) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4S8v6H1tMGz15Nd5; Tue, 17 Oct 2023 20:53:11 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemi500006.china.huawei.com (7.221.188.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 17 Oct 2023 20:55:52 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 3/7] RDMA/hns: Fix signed-unsigned mixed comparisons Date: Tue, 17 Oct 2023 20:52:35 +0800 Message-ID: <20231017125239.164455-4-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231017125239.164455-1-huangjunxian6@hisilicon.com> References: <20231017125239.164455-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 05:56:19 -0700 (PDT) From: Chengchang Tang The ib_mtu_enum_to_int() and uverbs_attr_get_len() may returns a negative value. In this case, mixed comparisons of signed and unsigned types will throw wrong results. This patch adds judgement for this situation. Fixes: 30b707886aeb ("RDMA/hns: Support inline data in extented sge space for RC") Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 2b8f6489ab3d..3daa684f8836 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -270,7 +270,7 @@ static bool check_inl_data_len(struct hns_roce_qp *qp, unsigned int len) struct hns_roce_dev *hr_dev = to_hr_dev(qp->ibqp.device); int mtu = ib_mtu_enum_to_int(qp->path_mtu); - if (len > qp->max_inline_data || len > mtu) { + if (mtu < 0 || len > qp->max_inline_data || len > mtu) { ibdev_err(&hr_dev->ib_dev, "invalid length of data, data len = %u, max inline len = %u, path mtu = %d.\n", len, qp->max_inline_data, mtu); -- 2.30.0