Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1217087pxx; Tue, 27 Oct 2020 10:58:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXSzGLnaZkm8h6DrZVxm7p1idIAD4sAwz3gBWbrjIsa8A5IQZy+rKotYw10u+f0f7pprdX X-Received: by 2002:a17:906:647:: with SMTP id t7mr3713223ejb.428.1603821499099; Tue, 27 Oct 2020 10:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603821499; cv=none; d=google.com; s=arc-20160816; b=E10oq3X6wdZgPKqrcbGmIi08u15XOT74nbItKNWkRpAVW4MlEAILbjPdJ/XXxuin07 qHDHPxkFVfppnt5sP8Xt+MmyX1QVct97b1pls+V3387zMHLxVfUSrr49fkQk+oLyMsfy PnKEMMRbcf02So5Em5wi4h1AfBzXfRzUC34ZVZTEJWNe5/AMj78J1OVCvEnttL5nqp3J Rqol0ecJTYth7eB/5o62EXX5nu8SaQOVdxqICtugaZEaFsOgidyOBGpizgC2w1Q5o1Tu Ziu7N/9zI28Ny28NmEpKsgdsBmcRXFffNXBt7k783rwZiXwyS2U5WSXEhhCpjJJjFMlM 7ApA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mpntDvb+nlGwi+3gAx5sECXyIU9g4V/JmpgP7xkx1CM=; b=hqwpKtW7yMwT+zlGWTqrCmUnrcNQWedIP51lKEwGZOsirYDAWWNfxn93EkHxS0gjRk pu68iFkzaH/tAbsjLcDrmvxKyPq3FlDzt7/GVIQyBt+4dEp6yASOvqdU8sWJfs1nX7OF R8lE7Mq6+BICmwjmlUpuZXjt4Va5hNc6JFdzXBkt06+JLIMd18qc03kJT2IZ57hnxp6P 9M9Fj95ZiU/Koi14RMlL5avhw9yz0Z7EgdLuRAoRAIms86fLCvock8H4sI1LFsBf53yv K95bQ8HtiQe73PTrn0t2Rtq2UaNN7BsnMPC4tUph+O+QB6sUxS65erimR4SWBhypKccT FMVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="BupV2u/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kt25si1467307ejb.438.2020.10.27.10.57.56; Tue, 27 Oct 2020 10:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="BupV2u/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1819107AbgJ0R1c (ORCPT + 99 others); Tue, 27 Oct 2020 13:27:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:53682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775786AbgJ0OxO (ORCPT ); Tue, 27 Oct 2020 10:53:14 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFA422071A; Tue, 27 Oct 2020 14:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810394; bh=9aZ3qkm/GBeZ1L2SoItoLPN9OKxJbgkXHOk1kq2t+Vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BupV2u/2z2+O4uG4bfCdRjTqUjbuCJv9bcW7xV8uM7nPLYWVrDl7q+8if5+WNZJOF MwI4IGVqKzPnFk+SYSmym+fElI+mA8aiGwiryPsTaewEHDY60eVn6E5m23Q7LFX4di ybqWVm8j5YyFUuzXSCYFiViffdqScuzHfV9+OmeU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurent Pinchart , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.8 124/633] media: rcar-csi2: Allocate v4l2_async_subdev dynamically Date: Tue, 27 Oct 2020 14:47:47 +0100 Message-Id: <20201027135528.521927398@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Laurent Pinchart [ Upstream commit 2cac7cbfb4099980e78244359ab9c6f056d6a7ec ] v4l2_async_notifier_add_subdev() requires the asd to be allocated dynamically, but the rcar-csi2 driver embeds it in the rcar_csi2 structure. This causes memory corruption when the notifier is destroyed at remove time with v4l2_async_notifier_cleanup(). Fix this issue by registering the asd with v4l2_async_notifier_add_fwnode_subdev(), which allocates it dynamically internally. Fixes: 769afd212b16 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver") Signed-off-by: Laurent Pinchart Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/rcar-vin/rcar-csi2.c | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index 151e6a90c5fbc..d9bc8cef7db58 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -361,7 +361,6 @@ struct rcar_csi2 { struct media_pad pads[NR_OF_RCAR_CSI2_PAD]; struct v4l2_async_notifier notifier; - struct v4l2_async_subdev asd; struct v4l2_subdev *remote; struct v4l2_mbus_framefmt mf; @@ -810,6 +809,8 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv, static int rcsi2_parse_dt(struct rcar_csi2 *priv) { + struct v4l2_async_subdev *asd; + struct fwnode_handle *fwnode; struct device_node *ep; struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 }; int ret; @@ -833,24 +834,19 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv) return ret; } - priv->asd.match.fwnode = - fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep)); - priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE; - + fwnode = fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep)); of_node_put(ep); - v4l2_async_notifier_init(&priv->notifier); - - ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd); - if (ret) { - fwnode_handle_put(priv->asd.match.fwnode); - return ret; - } + dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(fwnode)); + v4l2_async_notifier_init(&priv->notifier); priv->notifier.ops = &rcar_csi2_notify_ops; - dev_dbg(priv->dev, "Found '%pOF'\n", - to_of_node(priv->asd.match.fwnode)); + asd = v4l2_async_notifier_add_fwnode_subdev(&priv->notifier, fwnode, + sizeof(*asd)); + fwnode_handle_put(fwnode); + if (IS_ERR(asd)) + return PTR_ERR(asd); ret = v4l2_async_subdev_notifier_register(&priv->subdev, &priv->notifier); -- 2.25.1