From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D574C61DA4 for ; Fri, 3 Feb 2023 15:13:15 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1B769847; Fri, 3 Feb 2023 16:12:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1B769847 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1675437193; bh=MT/1DWmiNdOv0jG/vTHIL9cjtaEEbp2aoOQTv2f9NTg=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=aLSpt4e1dXApnYS22Scq2ueJK0nHaHgeprYQKTFJmYccoOHmGIyWKE8GX5b/YyoaO koKdHz+XvnwnM9CgvkrMYgxKqfeO7kjT7q/yiP9xyBFi/JP1B8RWKz29xohLRCO74B y5+aK2oUwWsUQLHX/zOtxgdpXhNNMLmfJzcgddiE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 47B6DF8053D; Fri, 3 Feb 2023 16:11:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E06AFF80543; Fri, 3 Feb 2023 16:11:47 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 612B3F80494 for ; Fri, 3 Feb 2023 16:11:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 612B3F80494 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=QK0Eqyz6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675437106; x=1706973106; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=MT/1DWmiNdOv0jG/vTHIL9cjtaEEbp2aoOQTv2f9NTg=; b=QK0Eqyz6aVl9Fl15wxQxPRDQK7JSchfx/iX01hWd9AULeJMP3aBIxve5 R9YGL/zc1t6rM+axPEpZD/q5T1LDRY0FmjckuccT0fo28qstaDLBi+vuw HbgKJkcHJBoORScqGXmUnDzlLo7NItZ4KBt337O2Dyw8rtiDGALcTRDWY pT6CHWrAC5YbBP7GDpHnnSWnOnsaE63bBWO/fdDMvXUUSUJBSnGA78/6j ghLLnzMt0UGLu9F40uCUtpRFk9VouNefaHQG0vOPLF6OQsOhGFqxdLS4O mg9igO4KOnlID8JpyrdLZ62sjm8V5YCKIgEgZrKg0uG7no0yTbO4ZAbuL w==; X-IronPort-AV: E=McAfee;i="6500,9779,10610"; a="330898278" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="330898278" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2023 07:11:42 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10610"; a="729290046" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="729290046" Received: from albuitra-desk.amr.corp.intel.com (HELO [10.209.172.145]) ([10.209.172.145]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2023 07:11:42 -0800 Message-ID: <0b49c924-5994-c1cd-a174-4a2e2cfaf0d2@linux.intel.com> Date: Fri, 3 Feb 2023 08:35:11 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.4.2 Subject: Re: [PATCH 1/2] soundwire: bus: Prevent infinite loop in sdw_ch_mask_to_ch() Content-Language: en-US To: Richard Fitzgerald , vkoul@kernel.org, yung-chuan.liao@linux.intel.com, sanyog.r.kale@intel.com References: <20230202154212.1098736-1-rf@opensource.cirrus.com> <20230202154212.1098736-2-rf@opensource.cirrus.com> From: Pierre-Louis Bossart In-Reply-To: <20230202154212.1098736-2-rf@opensource.cirrus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On 2/2/23 09:42, Richard Fitzgerald wrote: > Define the ch_mask argument of sdw_ch_mask_to_ch() as an unsigned > so that the shift right is guaranteed to eventually make the > value of ch_mask==0. > > Previously ch_mask was defined as a signed int, but a right > shift of a signed value preserves the sign bit. So if the sign > bit was 1, ch_mask would never become 0 and the for loop would > be infinite. > Signed-off-by: Richard Fitzgerald > --- > drivers/soundwire/bus.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h > index 7631ef5e71fb..28bedc919b78 100644 > --- a/drivers/soundwire/bus.h > +++ b/drivers/soundwire/bus.h > @@ -160,7 +160,7 @@ int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, > u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); > > /* Retrieve and return channel count from channel mask */ > -static inline int sdw_ch_mask_to_ch(int ch_mask) > +static inline int sdw_ch_mask_to_ch(unsigned int ch_mask) > { > int c = 0; > This patch1 is fine, but you remove this function in patch2, so is this patch needed at all? -/* Retrieve and return channel count from channel mask */ -static inline int sdw_ch_mask_to_ch(unsigned int ch_mask) -{ - int c = 0; - - for (c = 0; ch_mask; ch_mask >>= 1) - c += ch_mask & 1; - - return c; -} -