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 E427FC61D97 for ; Thu, 26 Jan 2023 12:54:09 +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 9FF32DF7; Thu, 26 Jan 2023 13:53:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9FF32DF7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1674737646; bh=Gbj75RVCvMcc1enTVnIeqLrxcO/2kEeRAemcs4S1yjs=; h=Date:From:To:Subject:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=nPjvYwqXxgRUvx2ZjHnrZhabOgcbDzxs31gPrJtK4LjDE/yw548IEsa7a7W6GOz8K xb5SXARZKXKmt8YtyqOIrwo31U/fG84sBnCKNsT5NKxdi6nZ1F90n22iQt+JK4d5w2 U4Q77+LX5ulQulsOU1tc2NxB8k8PvQFKC2hyDAJE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8DB3BF8025D; Thu, 26 Jan 2023 13:53:15 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6B7C2F8027D; Thu, 26 Jan 2023 13:53:12 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E3F84F80224 for ; Thu, 26 Jan 2023 13:53:02 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E3F84F80224 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=WiCCqTKs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=o9BVJXQ6 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E8F561FF40; Thu, 26 Jan 2023 12:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1674737581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fb8sBTQKgZCf6TAxBxFcTinrtnL4nnYNoq4E8lw+Nbo=; b=WiCCqTKsTH+tpt0hZChA7TpyjuumFyZTFjVO0Lb6bNHMt5yCgpe8rxSAdL+d8nrooGQGxs PaPRJzC0hxe7Xd6tu6VrCt1zIqvl+0Qk7uyU+deTR70pz4JUVD97S9Kg3NIQR7eCzIJBFj 4cNhQtk9V/vd5hAbdqewmSHhyPKRI/Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1674737581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fb8sBTQKgZCf6TAxBxFcTinrtnL4nnYNoq4E8lw+Nbo=; b=o9BVJXQ6VUJR8PrD3TMCo5h0cV70q6rH1UKd4ziNRh3axCVtcGAaXibH+j22p1GVg5aYs8 DRLa2lWLPLw3mxDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C328A139B3; Thu, 26 Jan 2023 12:53:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b5XrLq130mPfTgAAMHmgww (envelope-from ); Thu, 26 Jan 2023 12:53:01 +0000 Date: Thu, 26 Jan 2023 13:53:01 +0100 Message-ID: <878rhptq36.wl-tiwai@suse.de> From: Takashi Iwai To: Dan Carpenter Subject: Re: [PATCH] ALSA: pci: lx6464es: fix a debug loop In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII 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: alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org, Takashi Iwai , Maxime Ripard Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 26 Jan 2023 10:30:02 +0100, Dan Carpenter wrote: > > This loop accidentally reuses the "i" iterator for both the inside and > the outside loop. The value of MAX_STREAM_BUFFER is 5. I believe that > chip->rmh.stat_len is in the 2-12 range. If the value of .stat_len is > 4 or more then it will loop exactly one time, but if it's less then it > is a forever loop. > > Fixes: 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif") > Signed-off-by: Dan Carpenter > --- > sound/pci/lx6464es/lx_core.c | 12 +++++------- > 1 file changed, 5 insertions(+), 7 deletions(-) > > diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c > index d3f58a3d17fb..7c1b380a54c0 100644 > --- a/sound/pci/lx6464es/lx_core.c > +++ b/sound/pci/lx6464es/lx_core.c > @@ -493,13 +493,11 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, > dev_dbg(chip->card->dev, > "CMD_08_ASK_BUFFERS: needed %d, freed %d\n", > *r_needed, *r_freed); > - for (i = 0; i < MAX_STREAM_BUFFER; ++i) { > - for (i = 0; i != chip->rmh.stat_len; ++i) > - dev_dbg(chip->card->dev, > - " stat[%d]: %x, %x\n", i, > - chip->rmh.stat[i], > - chip->rmh.stat[i] & MASK_DATA_SIZE); > - } > + for (i = 0; i < chip->rmh.stat_len; ++i) Judging from the previous lines, the access over MAX_STREAM_BUFFER might be unsafe. So I guess a more safer change would be something like: for (i = 0; i < MAX_STREAM_BUFFER && chip->rmh.stat_len; ++i) Care to resubmit with it? Thanks! Takashi 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3C05C54E94 for ; Thu, 26 Jan 2023 12:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233955AbjAZMxG (ORCPT ); Thu, 26 Jan 2023 07:53:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231428AbjAZMxF (ORCPT ); Thu, 26 Jan 2023 07:53:05 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DA01632B for ; Thu, 26 Jan 2023 04:53:03 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E8F561FF40; Thu, 26 Jan 2023 12:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1674737581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fb8sBTQKgZCf6TAxBxFcTinrtnL4nnYNoq4E8lw+Nbo=; b=WiCCqTKsTH+tpt0hZChA7TpyjuumFyZTFjVO0Lb6bNHMt5yCgpe8rxSAdL+d8nrooGQGxs PaPRJzC0hxe7Xd6tu6VrCt1zIqvl+0Qk7uyU+deTR70pz4JUVD97S9Kg3NIQR7eCzIJBFj 4cNhQtk9V/vd5hAbdqewmSHhyPKRI/Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1674737581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fb8sBTQKgZCf6TAxBxFcTinrtnL4nnYNoq4E8lw+Nbo=; b=o9BVJXQ6VUJR8PrD3TMCo5h0cV70q6rH1UKd4ziNRh3axCVtcGAaXibH+j22p1GVg5aYs8 DRLa2lWLPLw3mxDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C328A139B3; Thu, 26 Jan 2023 12:53:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b5XrLq130mPfTgAAMHmgww (envelope-from ); Thu, 26 Jan 2023 12:53:01 +0000 Date: Thu, 26 Jan 2023 13:53:01 +0100 Message-ID: <878rhptq36.wl-tiwai@suse.de> From: Takashi Iwai To: Dan Carpenter Cc: Jaroslav Kysela , Maxime Ripard , Takashi Iwai , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] ALSA: pci: lx6464es: fix a debug loop In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: kernel-janitors@vger.kernel.org On Thu, 26 Jan 2023 10:30:02 +0100, Dan Carpenter wrote: > > This loop accidentally reuses the "i" iterator for both the inside and > the outside loop. The value of MAX_STREAM_BUFFER is 5. I believe that > chip->rmh.stat_len is in the 2-12 range. If the value of .stat_len is > 4 or more then it will loop exactly one time, but if it's less then it > is a forever loop. > > Fixes: 8e6320064c33 ("ALSA: lx_core: Remove useless #if 0 .. #endif") > Signed-off-by: Dan Carpenter > --- > sound/pci/lx6464es/lx_core.c | 12 +++++------- > 1 file changed, 5 insertions(+), 7 deletions(-) > > diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c > index d3f58a3d17fb..7c1b380a54c0 100644 > --- a/sound/pci/lx6464es/lx_core.c > +++ b/sound/pci/lx6464es/lx_core.c > @@ -493,13 +493,11 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, > dev_dbg(chip->card->dev, > "CMD_08_ASK_BUFFERS: needed %d, freed %d\n", > *r_needed, *r_freed); > - for (i = 0; i < MAX_STREAM_BUFFER; ++i) { > - for (i = 0; i != chip->rmh.stat_len; ++i) > - dev_dbg(chip->card->dev, > - " stat[%d]: %x, %x\n", i, > - chip->rmh.stat[i], > - chip->rmh.stat[i] & MASK_DATA_SIZE); > - } > + for (i = 0; i < chip->rmh.stat_len; ++i) Judging from the previous lines, the access over MAX_STREAM_BUFFER might be unsafe. So I guess a more safer change would be something like: for (i = 0; i < MAX_STREAM_BUFFER && chip->rmh.stat_len; ++i) Care to resubmit with it? Thanks! Takashi