From nobody Mon Feb 9 07:32:34 2026 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 80ED81C32FF for ; Fri, 30 Jan 2026 02:31:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769740320; cv=none; b=EcElresgm1cZFHlHzzevYQs/f9mz4AKSJjwQNzlfnaREw/Lac8o9EAwGLlBO6LBciLOiKd9sHP7eyD+P/X4ZNkt7Vu/O3Eh2WxnuC+SkvMxrGMYHr6PLTizx5ixN1vEsE/cP3m9N+xkdv7QPfinwECJTS804kuxv0kyHNmb2WFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769740320; c=relaxed/simple; bh=RlewUzsQnqRK/BfOkyEUTMO9ubuuVXujIi0e82Y7LD0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ehJX+C0ns1m084Rc4+AISB0WbnObtH+oR8glbxKhteSN/6WuC+vPM6qPNFIK/sKSIocn0kMM8tXmdj5S3Jlu6NgMC+E7WgBAtkkOqYM6WxrbbulOtmUednmwa/ftt0ZiqOehB+zSnx5ZzYQ3vgtyxLGl2bt6pNEVgUdzSzmSeRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=u.northwestern.edu; spf=pass smtp.mailfrom=u.northwestern.edu; dkim=pass (2048-bit key) header.d=u-northwestern-edu.20230601.gappssmtp.com header.i=@u-northwestern-edu.20230601.gappssmtp.com header.b=FPRLMATv; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=u.northwestern.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=u.northwestern.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=u-northwestern-edu.20230601.gappssmtp.com header.i=@u-northwestern-edu.20230601.gappssmtp.com header.b="FPRLMATv" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-662f65c7d8cso926796eaf.2 for ; Thu, 29 Jan 2026 18:31:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u-northwestern-edu.20230601.gappssmtp.com; s=20230601; t=1769740317; x=1770345117; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IZWRdRvUX/4o8E93YsgshqpXcbRbI3BTynBv7Avb9o8=; b=FPRLMATv41bfu2vqzaL5lG8Q4A2eI7KE/UVd6EiueeEgSDPEwPj5Hwwh2RQdSogU0j baV93tlX4v04vHj7pe0PUyMswdGkULlitpMD6lpJO80dqG7VhD0oMQlFcwHPN3m5nInF aK3Y7Y8mo6y8DiFs6JpWXNUfm/wGV5+3mXu79PauqG8l0FuYqMjPVzphNSkUKQZHtGlx Qg9pF1aL+Wul9eSJRU5/Q9hB6TJ3UpO3M6/hjXx8SLepHAkMMfcL70dYhD9tWLWci4Zh mIL5OpHE4MYi9+uemGczFGcgPvRF/Jtzn5DdfDOHyjlJm4OEpNvJ+KRfk6K4tTSn6RVM HugQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769740317; x=1770345117; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IZWRdRvUX/4o8E93YsgshqpXcbRbI3BTynBv7Avb9o8=; b=KvU2NxCpbvg4hHScHctBYIzpN+h4zC279/WJIOjSdyE2T835uVLZBelAii1HmfLpnY wylLSX2mLPBnPyFynBBX9XkWFQ6OaW9+M0wJpHBLAWPNSbez45N4nc/5Ege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:662:c161:206e with SMTP id 006d021491bc7-6630f3cdb13mr633553eaf.82.1769740317409; Thu, 29 Jan 2026 18:31:57 -0800 (PST) Received: from security.cs.northwestern.edu (security.cs.northwestern.edu. [165.124.184.136]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-409570f1273sm5029874fac.5.2026.01.29.18.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 18:31:57 -0800 (PST) From: Ziyi Guo To: Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ziyi Guo Subject: [PATCH] media: i2c: imx258: add missing mutex protection for format code access Date: Fri, 30 Jan 2026 02:31:54 +0000 Message-Id: <20260130023154.116038-1-n7l8m4@u.northwestern.edu> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" imx258_open(), imx258_enum_mbus_code(), and imx258_enum_frame_size() call imx258_get_format_code() without holding imx258->mutex. However, imx258_get_format_code() has lockdep_assert_held(&imx258->mutex) indicating that callers must hold this lock. All other callers of imx258_get_format_code() properly acquire the mutex: - imx258_set_pad_format() acquires mutex at imx258.c:918 - imx258_get_pad_format() acquires mutex at imx258.c:896 The mutex is needed to protect access to imx258->vflip->val and imx258->hflip->val which are used to calculate the bayer format code. Add mutex_lock()/mutex_unlock() around the imx258_get_format_code() calls in the affected functions to fix the missing lock protection. Signed-off-by: Ziyi Guo --- drivers/media/i2c/imx258.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index e50dcfd830f5..bc9ee449a87c 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -709,12 +709,16 @@ static int imx258_open(struct v4l2_subdev *sd, struct= v4l2_subdev_fh *fh) v4l2_subdev_state_get_format(fh->state, 0); struct v4l2_rect *try_crop; =20 + mutex_lock(&imx258->mutex); + /* Initialize try_fmt */ try_fmt->width =3D supported_modes[0].width; try_fmt->height =3D supported_modes[0].height; try_fmt->code =3D imx258_get_format_code(imx258); try_fmt->field =3D V4L2_FIELD_NONE; =20 + mutex_unlock(&imx258->mutex); + /* Initialize try_crop */ try_crop =3D v4l2_subdev_state_get_crop(fh->state, 0); try_crop->left =3D IMX258_PIXEL_ARRAY_LEFT; @@ -839,7 +843,9 @@ static int imx258_enum_mbus_code(struct v4l2_subdev *sd, if (code->index > 0) return -EINVAL; =20 + mutex_lock(&imx258->mutex); code->code =3D imx258_get_format_code(imx258); + mutex_unlock(&imx258->mutex); =20 return 0; } @@ -849,10 +855,16 @@ static int imx258_enum_frame_size(struct v4l2_subdev = *sd, struct v4l2_subdev_frame_size_enum *fse) { struct imx258 *imx258 =3D to_imx258(sd); + u32 code; + if (fse->index >=3D ARRAY_SIZE(supported_modes)) return -EINVAL; =20 - if (fse->code !=3D imx258_get_format_code(imx258)) + mutex_lock(&imx258->mutex); + code =3D imx258_get_format_code(imx258); + mutex_unlock(&imx258->mutex); + + if (fse->code !=3D code) return -EINVAL; =20 fse->min_width =3D supported_modes[fse->index].width; --=20 2.34.1