Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3970922pxb; Tue, 25 Jan 2022 00:17:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2xTY7MSB4v5DvZ8h+/FalNo8w4FFoLcXAwLHBzMYzDGDsv+w7+p6HaOkiBlFiAoc9S2cw X-Received: by 2002:a05:6402:486:: with SMTP id k6mr19571422edv.330.1643098678332; Tue, 25 Jan 2022 00:17:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643098678; cv=none; d=google.com; s=arc-20160816; b=CWF96QeMK+rLgtPm7U+nKkZD8d0lTIzcsTnfBuJT8vJy3IKBTQXBnSY5lRx8kiezPj w1E/WSY0gZvh5W54lb2tKd2OCYLuhzz+C6uyW22L/oM8x691z2kzFivOkn64X4FwCEGq qzT2mJa3ENSGE5i8YE5Gbt4V2h9gRgXicO9tCKkWb0SncMvDJ8FGJpcrA8QOODnITX1Q +zNGWpnidMU9zyK3VLM3ishDfHnWUF0SrcTfziZl+FsfjESsWLfEiPTalX0COPvBgxtK /qla8wQF6QpIYR+J9WLBFY0FHBHyGSXTycZXcfLjwyT5Bw0jJQ9HYO9b8nKZ/qInJW64 /lkw== 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=4WOJtEZ7Tc7aXzwE0I4vx7GePgt6uUJrtyHTreLmnq4=; b=Lx6bGm+jnnkt1Z2rL5shIVPsyLwbO6PjAgkiGTsNW2wIhROb67K+iL0d5/Cr9ZIbw8 GJjyru37/haapXXsugzYyINkDnm6+fVfYWvFu4F+ftCoaUUOtYz1Kw0u2Vdb/m7cou8+ A7GXz6GWAS/gU9PEzw5TwzPPrAK79Mpr8r/B7ujl+4LNE+vMnj8BJHOVvrUR0SvbYSnP vp6gzTZH6e7bLxTCacF3Uv/R7ko4wAqWKIKQq/239mgFJH0n/0+4MfuNIt5Bj2ZTeLCm bsTqBRKkSkXLrPOWPDreOH6Z9gtRgA+RIq41Tnu2xUpn8Im1Eg3UU5WKorH3L2L/NYwp AFHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/2Xr4gJ"; 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 hr36si3937200ejc.955.2022.01.25.00.16.57; Tue, 25 Jan 2022 00:17:58 -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="n/2Xr4gJ"; 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 S3411611AbiAYAeK (ORCPT + 99 others); Mon, 24 Jan 2022 19:34:10 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47494 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1455232AbiAXVfD (ORCPT ); Mon, 24 Jan 2022 16:35:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 55991B8105C; Mon, 24 Jan 2022 21:34:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E888C340E4; Mon, 24 Jan 2022 21:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060098; bh=C1j676FUP8iWuGVMyB82H13nsJjOvitU5NC+K+waxcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/2Xr4gJqLYRpWTah8xtQIR0nqDKldX6fyJKow1kK2XmArf7Zj8fGx/UKOHvzMx7u zdqwG/9ciH6zgot3gbs/9bHpegkFLQab65YIA012cdPFBa2sq5ATdXA2Ux9BK5/PEH D+VmhkKecnnr+GAsFMIUx+YL0NhyMapFv6r1qyDI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Nicolas Pitre , Alexandre Belloni , Sasha Levin Subject: [PATCH 5.16 0795/1039] i3c/master/mipi-i3c-hci: Fix a potentially infinite loop in hci_dat_v1_get_index() Date: Mon, 24 Jan 2022 19:43:04 +0100 Message-Id: <20220124184152.025168739@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Christophe JAILLET [ Upstream commit 3f43926f271287fb1744c9ac9ae1122497f2b0c2 ] The code in 'hci_dat_v1_get_index()' really looks like a hand coded version of 'for_each_set_bit()', except that a +1 is missing when searching for the next set bit. This really looks odd and it seems that it will loop until 'dat_w0_read()' returns the expected result. So use 'for_each_set_bit()' instead. It is less verbose and should be more correct. Fixes: 9ad9a52cce28 ("i3c/master: introduce the mipi-i3c-hci driver") Signed-off-by: Christophe JAILLET Acked-by: Nicolas Pitre Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/0cdf3cb10293ead1acd271fdb8a70369c298c082.1637186628.git.christophe.jaillet@wanadoo.fr Signed-off-by: Sasha Levin --- drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c index 783e551a2c85a..97bb49ff5b53b 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c @@ -160,9 +160,7 @@ static int hci_dat_v1_get_index(struct i3c_hci *hci, u8 dev_addr) unsigned int dat_idx; u32 dat_w0; - for (dat_idx = find_first_bit(hci->DAT_data, hci->DAT_entries); - dat_idx < hci->DAT_entries; - dat_idx = find_next_bit(hci->DAT_data, hci->DAT_entries, dat_idx)) { + for_each_set_bit(dat_idx, hci->DAT_data, hci->DAT_entries) { dat_w0 = dat_w0_read(dat_idx); if (FIELD_GET(DAT_0_DYNAMIC_ADDRESS, dat_w0) == dev_addr) return dat_idx; -- 2.34.1