From nobody Mon May 25 09:57:53 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 5B2CF3DA5A1 for ; Mon, 18 May 2026 05:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779083198; cv=none; b=RypVKKI3Fk/YgBcR6+asX/Oeond73V67iNocL6tD7OuLspOKuYvo/I07QhRwls8QmEVrak7flw688/g61iJxeEvwSzO+YxkClepd3rp+mBtxPMwyfwBuJ27w03yXSKJXO2oG6C77tt0UAFvHTVhtYT/CKAJVWwTl3rhFhlMZ/3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779083198; c=relaxed/simple; bh=nzlZAviRkiUVtqGLGxPY21P8av4JBOU+eehvWsyKAQY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fqi5t12hKCZpa1+FZAcB6c1Dn3j4qW9flEzbaCc3trxt0BdWw7dcUm1mALfK2S+kqamastQvi5gpatUsuK/N4iSjDEGGVvClAy3E+TAolq92VJNMN4KV311hbj68LX2NhbdoXNxnIRGQ+hEgeR4o9C8YL1NibRSdMc8+bYM37Ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P9QNAxsT; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P9QNAxsT" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-83945063f70so1352980b3a.0 for ; Sun, 17 May 2026 22:46:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779083188; x=1779687988; 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=b69/f1IaWhKRvn/Sm6atJ8FHYkT6bLRfEDI5V7g2TEc=; b=P9QNAxsTYoCrtJAqRipyQ/5O6RJfofqhViHXq7vMDk11nwfZiTTDlY2nZl9FOvULac EWK5RUD7xvMsLBNqY0BjihuUsu4DSoOyE2Zx+KcXs6G2aaPcMQjE+XEC/exK0C8jRR7i YAbi+JF9HDvGtoqQYNKeWxrvbinVUItTJJ9ztQGcOiqGmlUTn1V5PyC2IpxIsnvnPEK7 Mgda3Z0/wF+0rP4xAKF8GrUk4YW+WMUGJZTou4L1DJVCugK76sBul2Zz07qlVBl5Jab7 vihEGXe1Z0DAMMKN9IrFgwal/ixkskv0rl6BYgOcQjOM8CkTJoz8ZhWaDv1B2O2NIU4s 2ewg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779083188; x=1779687988; 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=b69/f1IaWhKRvn/Sm6atJ8FHYkT6bLRfEDI5V7g2TEc=; b=q8VeM9m8ejCFe+/lbFgQMM8m5nM57koyXWyPJEaw0f0gZq6OXCDQYvl3AIJKiFHTM5 h4cIb8dy9TztfJ1xYArs9B1dKRN0sNr8RODRgUwJ1XudoYrixCrpYPGUTvF2TLHctPyL D2RfUHV49E2daUnbkG1aNN8lz/IfXlRINrV+NSlRkMNAmVi1XVCh1opc2TNiSsnrREev 8OSk0Al3WFlsEKdC7kTG1o1iBbKH2VKE6YcLlBEJHiiRFrakMrPDn5OtDufeZzT8Wj7N ISJ/WUttD9sQcp2U9vXfJy1viwFrha1MfO+3g3TyVYuCI+G/zdVgrCP7i7d6DPsPnN0u Hajw== X-Forwarded-Encrypted: i=1; AFNElJ+ffujcEpjgaNet610RYKkrGxzzkd8jD+EbmDM1sjD90Xs4pEAImd3k1HaNE/iufJskX19ppIAaokV6Jdg=@vger.kernel.org X-Gm-Message-State: AOJu0YxdVsGulVwj0KCp/wa49ZYbMO81Fq+5EqkiBXvnnprHpRkOVK8s F7x7crkVrxZhwsrGDXDJWlWygHP3Pf6CsjGI+aZRERdkHn/4p/liFYUS X-Gm-Gg: Acq92OEyYzFZL+8jZmW5ZVbI4XtPAXIrhkaHf+TaL7YRvCyocTCaDfnUbjPcI9VSKGT EiS7Tkym3vL65lYqR+iIXGKXyo13YOlZUpWq7OEDbtgyF8dBVEUup3nQjipi2G+l6Z5UwfrWKGx hR2nxYuVSx2MSNZQTV2xrR8ZvDs4IKwDNVF1aRa1+jzybcQ7mvXxlDjvE8KO1B3i/wv84QYNAVg cufE5PKnLk6UDiQGDErfrNY0g2YRAed0T1dvJWay5wRBh8zXb/BMPgTeIVpZFboQraQedbSaoNt kpx+GLSNsnwDtq2CwE3RUCVRsjxzUUVtwpylV5dH3VP58iGZeF2FNGoXDD/GOiUr61D75Scln5M 53zW+x5DCAOMK5qEodgYGCv9e2liCxlsb4lOjbKbIbMT4LlfK4h2QSQ8H53rZhu8YNK7sgMI3fv cSwsiY2siVuTdunlTn X-Received: by 2002:a05:6a00:3028:b0:82f:2aaa:c14c with SMTP id d2e1a72fcca58-83f18e770a7mr14563893b3a.16.1779083187983; Sun, 17 May 2026 22:46:27 -0700 (PDT) Received: from lgs.. ([2001:250:5800:1000::f280]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19c5c020sm13344918b3a.30.2026.05.17.22.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 22:46:27 -0700 (PDT) From: Guangshuo Li To: Neil Armstrong , Mauro Carvalho Chehab , Greg Kroah-Hartman , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Maxime Jourdan , Hans Verkuil , linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li Subject: [PATCH] media: meson: vdec: avoid double free on video register failure Date: Mon, 18 May 2026 13:43:18 +0800 Message-ID: <20260518054318.979147-1-lgs201920130244@gmail.com> X-Mailer: git-send-email 2.43.0 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" vdec_probe() allocates a video_device with video_device_alloc() and releases it from the err_vdev_release error path if video_register_device() fails. This can double free the video_device when __video_register_device() reaches device_register() and that call fails: video_register_device() -> __video_register_device() -> device_register() fails -> put_device(&vdev->dev) -> v4l2_device_release() -> vdev->release(vdev) -> video_device_release(vdev) vdec_probe() -> err_vdev_release -> video_device_release(vdev) Use video_device_release_empty() while registering the device so that registration failure paths do not free vdev through vdev->release(). vdec_probe() then releases vdev exactly once from err_vdev_release. Restore video_device_release() after successful registration so the registered device keeps its normal lifetime handling. This issue was found by a static analysis tool I am developing. Fixes: 3e7f51bd9607 ("media: meson: add v4l2 m2m video decoder driver") Signed-off-by: Guangshuo Li --- drivers/staging/media/meson/vdec/vdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/medi= a/meson/vdec/vdec.c index 4b77ec1af5a7..2994e46cbc25 100644 --- a/drivers/staging/media/meson/vdec/vdec.c +++ b/drivers/staging/media/meson/vdec/vdec.c @@ -1074,7 +1074,7 @@ static int vdec_probe(struct platform_device *pdev) mutex_init(&core->lock); =20 strscpy(vdev->name, "meson-video-decoder", sizeof(vdev->name)); - vdev->release =3D video_device_release; + vdev->release =3D video_device_release_empty; vdev->fops =3D &vdec_fops; vdev->ioctl_ops =3D &vdec_ioctl_ops; vdev->vfl_dir =3D VFL_DIR_M2M; @@ -1089,6 +1089,7 @@ static int vdec_probe(struct platform_device *pdev) dev_err(dev, "Failed registering video device\n"); goto err_vdev_release; } + vdev->release =3D video_device_release; =20 return 0; =20 --=20 2.43.0