From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 227E93A6415 for ; Wed, 4 Feb 2026 09:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197764; cv=none; b=sdiEcd99F+eBwU4Lucw/n3Iw6TMsYMdv5KUT9S3eV132EdEQBcnK57EsW+JCw0LaWv2imEWLoLDu/B/ogJ6p//OuL2JVzQ+v5DEncJ00fv69wdqn/tT0kaB9Io0NabBq/JIcMHnD4ymJxmUBKqtnSIGQtdkziyA33nr10uTJeKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197764; c=relaxed/simple; bh=vOMGGu93PglgXkTO0WCCDVo+GGCEa1SqzloTFk1irsE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yl1l9v/uDMsgTIKpxPhhV3QdhajEm66Io3SdZ8FrTERwF3y5DVZEuumGxsAok6RZ3R6XdkxM/CqINHbZKSDa3UFZXxMWPMrXnQeG4g/06F3RW35Md6sjezsemEHmuwt80elScdguSuZy+Z6dHzkWBrBJbPQqmawbjsyPZkuh+DM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rcvX1l5f; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rcvX1l5f" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4327790c4e9so4164012f8f.2 for ; Wed, 04 Feb 2026 01:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770197762; x=1770802562; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uJ0/1Y469omco+KfEh9cubrhsWGsz73BeQRvDS8QnaA=; b=rcvX1l5fEWzw2bvFi7Gg9eYFpqtbvX/30fnHLNlOxvX2kLZizqn1X2CKjyPmC2qHjn Mpbnnk1EecB9cltLHx4bBzVMwLbQueyzqCXZrMvnW/kv3Hllg3G7hPogqo01HPgGvy8A GPGtN2d1atfeg7JopmBEoAyzsjLQ5afLrswoQVKmcJQnrpqS3b5qpfMTyVWVktbwUyjN 0t9S6siTKj8wkDZOV66BosHj7vM+K8pnxNpSbnGNkBd6zKfbgtyFRF4f3jr+bKvQeEGy lM7fjQRuFgEcX3Yd2o/mQLPZcZBn0BPOM6pFc8gw1jJUybEogRBuifi3YfehvMWzmHpY EeaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770197762; x=1770802562; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uJ0/1Y469omco+KfEh9cubrhsWGsz73BeQRvDS8QnaA=; b=Rrm2fa7xCWwetvYWQAVu9rd9mUDrSRFWTK7cfmDGs1GJBBl0k+7Sw6G+qBdihI/G2X E8e9n45KLvlxTn4BCPhwUCIKEgVuC5vZl7IausW4FikToX/LxPKwFUR5lHp7WEG8341M pG3y2TsfkAbU7lS1lAVTQlXl2h/yQBwiF7hDbJGYwA1KfeZZ+CBi/fFSE3bk3EJ43pvr BMmHuPE6FWEMLzHzI+JEl04psPOBTWxrMCQObh7p5jvC2+DuvgxvcorI5K+CLc6tORZa DLQkmeLaXHGV613qrfDBjM1YcKGEO1d9NcXvQO+dhK5vHBu5itwAkk+MjvGKCF0gzD1f 1QyQ== X-Forwarded-Encrypted: i=1; AJvYcCXZamQpThGB6l12Khs5zZ0yqPwSv5UM+lA9IPwjGwbavIq//LJJjCirQ5OquIqm5pB45G4v7LJkVdGI0DM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5OsSczJtxa0Hw5m2dQkQFx2IFPllFYlHuh/i3YIj82BVLFGYo c7BsbuNSUv5qw/FYu4dW+FcQS3q1x8I5sqp0s+b8vv6R8bAFSWu3tsccQZSia4QtHD4= X-Gm-Gg: AZuq6aK58jMEi6wNtzwXPesOz4xmG6w0nB25wePinFEMVqWBjsgfUXBZlIZsATbw1Mo cT9krxkslTWcl/k/Ce/JeI8d6PHqamZwf/ul0O59oY9Ynr1UbjRd9Kzr4/G2XRohdoP5wtJ7x1U PHpy0ak8DnpnYCuJqtdtvsb4cJ804G5MOu0g9/uCL9jHe7iYu1SHDjnPU4FFiQmVdNj71kC2t/M Jt+qwI0lhP8O4MWVHdFl5s+gGpfdqKKV0/Tsc7+lSF387btDLgussiptLVIBrh8csrUwFCruRvd RcIncZeIOCw4yUDB7oZsficvCo+xPDs88YDVUDC8pEGNf1WMu1Rd7IPrzGeg3cx7YskYB39m8JR cJuiQlhNC0laceHezz/9fq/d1YNiFKFkIY495fDve/vpqUUYvItpcZ7cHOdtLen8IU4mWe7MwTD 2QduCFGaTO+vM2bYLXWZTNJ6+MVdE= X-Received: by 2002:a05:6000:4211:b0:432:c05b:d8c7 with SMTP id ffacd0b85a97d-4361805955amr2906170f8f.49.1770197762404; Wed, 04 Feb 2026 01:36:02 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43618064844sm4902192f8f.42.2026.02.04.01.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 01:36:02 -0800 (PST) Date: Wed, 4 Feb 2026 12:35:59 +0300 From: Dan Carpenter To: Minu Jin Cc: parthiban.veerasooran@microchip.com, christian.gromm@microchip.com, gregkh@linuxfoundation.org, hverkuil+cisco@kernel.org, laurent.pinchart+renesas@ideasonboard.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: most: video: fix potential race in list iteration Message-ID: References: <20260203112800.3351763-1-s9430939@naver.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260203112800.3351763-1-s9430939@naver.com> On Tue, Feb 03, 2026 at 08:28:00PM +0900, Minu Jin wrote: > There is a pattern in the loops where the lock is dropped > to call a specific function and then re-acquired. > > The list can be exposed during this short gap, creating a potential > race condition. This patch fixes the problem by moving nodes to a > local list while holding the lock, instead of using the > unlock/lock pattern in the loop. > > Signed-off-by: Minu Jin > --- > drivers/staging/most/video/video.c | 22 ++++++++++++++-------- > 1 file changed, 14 insertions(+), 8 deletions(-) > > diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c > index 32f71d9a9cf7..e7db58e5746a 100644 > --- a/drivers/staging/most/video/video.c > +++ b/drivers/staging/most/video/video.c > @@ -121,6 +121,7 @@ static int comp_vdev_close(struct file *filp) > struct comp_fh *fh = to_comp_fh(filp); > struct most_video_dev *mdev = fh->mdev; > struct mbo *mbo, *tmp; > + LIST_HEAD(free_list); > > /* > * We need to put MBOs back before we call most_stop_channel() > @@ -134,12 +135,15 @@ static int comp_vdev_close(struct file *filp) > spin_lock_irq(&mdev->list_lock); > mdev->mute = true; > list_for_each_entry_safe(mbo, tmp, &mdev->pending_mbos, list) { > - list_del(&mbo->list); > - spin_unlock_irq(&mdev->list_lock); > - most_put_mbo(mbo); > - spin_lock_irq(&mdev->list_lock); > + list_move(&mbo->list, &free_list); > } This loop moves ever single item in the list one by one. You could do it in one step instead by copying the list_head and setting pending_mbos to point to itself. Same in other loop. regards, dan carpenter