From nobody Mon May 25 05:12:55 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 C249B3FB044 for ; Mon, 18 May 2026 13:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779109785; cv=none; b=jTQZd0MnQ45zFL37WDgTTHjHkVP8HnVRNQhSCTicFoQrUXQNbE6Ccp19m3THGwiJt1OgER18AraT143Y9m6nymZP/P8gGCTzehmDLVcl8Vl+RwGmrEOu+eDAy5NfnMTI4pUXkfIAVkCEAvF1S+DwO5kSS+ZW/MNyeVo520UMwhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779109785; c=relaxed/simple; bh=NfclscNBSnSTPaF1Uyz6avlOxZwSfStDxpuf2uV4hL0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kN8/7IdRJcOQ3GFhvrVLo4RvXpVKO1yPp6J+QCWKSoA6vaL9/vwP3R6tJ/avFjyiIzxoAoz5V6zzL/nwKYdlKkeOZkwNZHKdW4Q07RRy30bw0K7lPZ0UDRCjk1OgR/XT0ZMIXuRBwofNIMyi03vcQh8Wlglw8fN1XqvonXZFSvk= 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=NRLZxD+I; arc=none smtp.client-ip=209.85.216.52 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="NRLZxD+I" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-36643b96b99so2137754a91.0 for ; Mon, 18 May 2026 06:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779109783; x=1779714583; 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=rAloUi+mRjxqQ41OzwWcNwZlapgA44SFMZ3iPQ72NV8=; b=NRLZxD+I4JD4SV0Hfk8nKzyUMuY0BowWSfQwXcURdo9uUZo/SBRMHplq/JUP41WiEv uw/Z1mDVcXuvLB82jtq398ClLB16omlp7RDhD0qMVkqsHT24mWhdcwHd8AO6hAfelfsd qEwfRcAxvb29NhZTpjPcEt9EflaRfStoQTDjE5labRLluY1BkA2k2ETxzmtZMzeZzvaq iZ3MvOtC2GGpXbV1/xqJakrFjS3ZaAmoPNZAOzm6KjNvdxbFwMGnr01TpALtMEYZZWr7 QIKl/oiMWftcqbxgFA2K/0P5jeYgLLIx2Q0MLbYDJVb4Iilid10VXqYONAlyu8UM7j96 GH1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779109783; x=1779714583; 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=rAloUi+mRjxqQ41OzwWcNwZlapgA44SFMZ3iPQ72NV8=; b=ppuLujiDbUX/kKQ44nykWS2LPOjLknuAHzX2txNxAv15bm4PVJANOQy/nG5CyPeEx/ kX6+B92bhIWtxO1OYj7pcPnuN+uQ0gIlRB6MO6HZAkxBEo41eTuYPLtrCWme3Ze78PUa A7pgSKbZKh0fIxl9g0nHoTJwwzCgqfd/avgeJLWd1wfpLPOk6n4M1oIXhKZjb4j8zUZS NCyezR0yHrTAMY915z7oSL32WQADLm529KjlX4yqSv2x4UeKykWLtfW71qVqmloesrEf D5bS34tV0EPkbPCbFubxlVpwJX/CvGiOu57ggCEVSRfCc02ddyNDq9G9KauDTpwwK1MZ iahA== X-Forwarded-Encrypted: i=1; AFNElJ9CAwKdtJaJGZfMwpRwpFIpVgAXOsZjQQxcnAP1FeZE6KhDJ44Grre3KBF3CgDpKGPcn6Vnoke9cAl34jY=@vger.kernel.org X-Gm-Message-State: AOJu0Yyo97+2N/yqOgc7fQr545XYmIsO8K9Uh/MtP71H7YaCmV0SvDmr hdxU1LRjnUtDIdPiOs8BdI+6+d6n+S8T+aztUiGnPbVckluVc17vxAbM X-Gm-Gg: Acq92OGcEuawRNXcTFQQAGtR/8AfurI959mBT4BOexUYlMcxLUnB9nVaaxvc5LNmTF2 Sl7kJz0w3ATmfhtWajbkPmjlJNe/rlSuz0hyk1C/CSQf1IZIPewUfQXZaFSRwcFKnaI2Gfnpzeg 1DkvSybU4LohoikBQH1MDwkp91+vNQxjrMrui3aZHZ3wCR2Xbeg4chwk2PhnTHo/f+vDiiNIU73 8QboMvcDCbQ+TF1JCZa6YtUBF2q5xFGGfLpZZms/xrxY7yGluRQKCBTWpz2kUKvzCSrTXN/dEEE Irbqy16bNQ3W5DjduehciwwR6EWZhRccgKvT80E9/UoWKXxW9saZUFOHf1+FTzjZ0LUmmrwVgew mSZEYNT2jF2VyoJ/ibplD5U2PB00ugPeIbMeqtGiCriMq2CWGGa5GVouJQR683weFSdjX9Kg3JM MDjmyTTsvHSMuJpk2Nn/dV X-Received: by 2002:a05:6300:218a:b0:39f:2dd0:65bf with SMTP id adf61e73a8af0-3b22ebe1bb6mr17937148637.28.1779109783131; Mon, 18 May 2026 06:09:43 -0700 (PDT) Received: from lgs.. ([101.76.249.46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f1966471dsm14863375b3a.6.2026.05.18.06.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 06:09:42 -0700 (PDT) From: Guangshuo Li To: Marek Szyprowski , Andrzej Hajda , Mauro Carvalho Chehab , Joonyoung Shim , Kamil Debski , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li Subject: [PATCH] media: s5p-mfc: avoid double free on video register failure Date: Mon, 18 May 2026 21:09:29 +0800 Message-ID: <20260518130929.1003652-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" s5p_mfc_probe() allocates video_device instances for both the decoder and encoder and releases them from the probe error paths if video_register_device() fails. This can double free a 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) s5p_mfc_probe() -> err_dec_reg or err_enc_reg -> video_device_release(vdev) Use video_device_release_empty() while registering the decoder and encoder video devices so that registration failure paths do not free them through vdev->release(). s5p_mfc_probe() then releases each video_device exactly once from its error path. Restore video_device_release() after successful registration so the registered devices keep their normal lifetime handling. This issue was found by a static analysis tool I am developing. Fixes: d0ce898c39bf ("[media] s5p-mfc: Replaced commas with semicolons") Signed-off-by: Guangshuo Li --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/med= ia/platform/samsung/s5p-mfc/s5p_mfc.c index 32eb402d439c..75abb0a8b7a9 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -1376,7 +1376,7 @@ static int s5p_mfc_probe(struct platform_device *pdev) } vfd->fops =3D &s5p_mfc_fops; vfd->ioctl_ops =3D get_dec_v4l2_ioctl_ops(); - vfd->release =3D video_device_release; + vfd->release =3D video_device_release_empty; vfd->lock =3D &dev->mfc_mutex; vfd->v4l2_dev =3D &dev->v4l2_dev; vfd->vfl_dir =3D VFL_DIR_M2M; @@ -1395,7 +1395,7 @@ static int s5p_mfc_probe(struct platform_device *pdev) } vfd->fops =3D &s5p_mfc_fops; vfd->ioctl_ops =3D get_enc_v4l2_ioctl_ops(); - vfd->release =3D video_device_release; + vfd->release =3D video_device_release_empty; vfd->lock =3D &dev->mfc_mutex; vfd->v4l2_dev =3D &dev->v4l2_dev; vfd->vfl_dir =3D VFL_DIR_M2M; @@ -1416,6 +1416,8 @@ static int s5p_mfc_probe(struct platform_device *pdev) v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); goto err_dec_reg; } + + dev->vfd_dec->release =3D video_device_release; v4l2_info(&dev->v4l2_dev, "decoder registered as /dev/video%d\n", dev->vfd_dec->num); =20 @@ -1424,6 +1426,8 @@ static int s5p_mfc_probe(struct platform_device *pdev) v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); goto err_enc_reg; } + + dev->vfd_enc->release =3D video_device_release; v4l2_info(&dev->v4l2_dev, "encoder registered as /dev/video%d\n", dev->vfd_enc->num); =20 --=20 2.43.0