Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3957249pxb; Tue, 2 Mar 2021 03:03:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq61Mx81QnqNOIZ2CAjkQimpxL7VPHwNDK+Hr2WzwgdqHE8aK3Lmv9YiSWPxCsFfU53SCf X-Received: by 2002:a17:906:4e17:: with SMTP id z23mr18758920eju.439.1614683013160; Tue, 02 Mar 2021 03:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614683013; cv=none; d=google.com; s=arc-20160816; b=ZeWNTwR0d15PJj4V7fYyqh+fqt1b7aA7CJYAEkw/gAn+5/0xZE5zOqBQAAU0bRm7RB wDqhJ/SahBWl8Kd2NoV0kJXgcp5Z5lJ5+SrJqx0SbsdJN1tqNrSPcUGgRByb3MCEXW70 8fDFer3htfnzWgVqi2UaXlYicheL8zCfr0e0fdum0OF9FGE99SDgjy0YOWe2CTmpKU9r OCXcxOwa+Jnpdx5qKGD/Ef8im/+15YT3yNfK3Hy05U6sJs1e5oYIltnLJuu311uwjPAZ aqOHkCetvadr+w/pDGr0STlLsSyEiSIdzM6H0uRVbrBUqLFr1Fi2QwsVveRw78dy2SIb 2lJg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5rvdN98UuLpSOIDye6SixrisL3lB/kPnM082zXJblaQ=; b=RtOlvYPxZU7Mf+floxfeO/lnfuKyvMoAjdQ4RV8sTLCph8t8bRFgjhORc0q7uWRt86 t4Q6BtzxZb+hn6UMTwhq/ZMErWdmJLCkE7EvUO2O+Ct1bSh4YahWqVV4CPTQp/Guc2EP Uf4fzelS3YzQgfpBWLHWTQTk9SNQQrcnqPLIRm6qmBDYhKiLw+wE55RIFVPLHhLMD2Sl t+zotG3efP8fSSFaZMjAdBO22wWG5xsK85+00ycGtqWQerFWUBflchBtIRvlk/JxIstG +aK36FdarJWjJxwXCEsT26v5sPYseNRHwbRQoLGugRRSTFtuDeJZq+mr0Q1FfBWGgYwK AhLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ool+dIns; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh9si6194341ejb.85.2021.03.02.03.03.09; Tue, 02 Mar 2021 03:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ool+dIns; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380338AbhCBBu2 (ORCPT + 99 others); Mon, 1 Mar 2021 20:50:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:48586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241705AbhCAT2q (ORCPT ); Mon, 1 Mar 2021 14:28:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B92586504F; Mon, 1 Mar 2021 17:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619122; bh=YI0eMn0QVMHl6mOr6ihrj7Dc/tcvgD1OP8w3fYaMhmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ool+dInsCbIltivQALA5SkcsQKpE7/TmiA+3Nk+hctPZ1AwoyiLSK8rHY45XkE6/t fXvAuw9TiVd9xlrqI+8VuwlNM6K4lpVfVSgrT2p/dT9rurSImU7HQQePY7CY1XWhYv Mn9mzDSLxYCsPx68JFZQXVlbAv/X4zZehfrO7xE8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Bloch , Parav Pandit , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 340/663] IB/cm: Avoid a loop when device has 255 ports Date: Mon, 1 Mar 2021 17:09:48 +0100 Message-Id: <20210301161158.675209163@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Parav Pandit [ Upstream commit 131be26750379592f0dd6244b2a90bbb504a10bb ] When RDMA device has 255 ports, loop iterator i overflows. Due to which cm_add_one() port iterator loops infinitely. Use core provided port iterator to avoid the infinite loop. Fixes: a977049dacde ("[PATCH] IB: Add the kernel CM implementation") Link: https://lore.kernel.org/r/20210127150010.1876121-9-leon@kernel.org Signed-off-by: Mark Bloch Signed-off-by: Parav Pandit Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c index 5afd142fe8c78..8e578f73a074c 100644 --- a/drivers/infiniband/core/cm.c +++ b/drivers/infiniband/core/cm.c @@ -4332,7 +4332,7 @@ static int cm_add_one(struct ib_device *ib_device) unsigned long flags; int ret; int count = 0; - u8 i; + unsigned int i; cm_dev = kzalloc(struct_size(cm_dev, port, ib_device->phys_port_cnt), GFP_KERNEL); @@ -4344,7 +4344,7 @@ static int cm_add_one(struct ib_device *ib_device) cm_dev->going_down = 0; set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); - for (i = 1; i <= ib_device->phys_port_cnt; i++) { + rdma_for_each_port (ib_device, i) { if (!rdma_cap_ib_cm(ib_device, i)) continue; @@ -4430,7 +4430,7 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data) .clr_port_cap_mask = IB_PORT_CM_SUP }; unsigned long flags; - int i; + unsigned int i; write_lock_irqsave(&cm.device_lock, flags); list_del(&cm_dev->list); @@ -4440,7 +4440,7 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data) cm_dev->going_down = 1; spin_unlock_irq(&cm.lock); - for (i = 1; i <= ib_device->phys_port_cnt; i++) { + rdma_for_each_port (ib_device, i) { if (!rdma_cap_ib_cm(ib_device, i)) continue; -- 2.27.0