Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp821193ybl; Wed, 4 Dec 2019 11:25:47 -0800 (PST) X-Google-Smtp-Source: APXvYqwzxof+enxyNopW27fQIXn9Y/yHdkdXv0/5qvSwl1aSJ9HyfxZ/DECPEZalZ1vXsT2A4B9m X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr4082314oij.176.1575487547111; Wed, 04 Dec 2019 11:25:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575487547; cv=none; d=google.com; s=arc-20160816; b=QeDvWfBkDkOfG9ShXEDUYvph18hgC3dAFdZQD5BUhcJluDdr0TV3EkNElR1FqfpbDb TyCxFC9bjsWWouhRvsHwHb1Rxxh5V22+jVpmqsqTHk+7YieNT4hQqrOyTOL6+bqcPeu3 pZ08YS6fDdH5thsabXq6QMiz84Xp7Ed9xTLHBeSv19WnJEmC5VH9iyqnstj1U+oXJMZw mzWSdsWtl8SGJau/KN5JOonACUFJAJAPRDzlDRAZbQcVefa4kA9QiMDYdGt9k9U3S80E 6whmaUVGk0CFE+LMpci1zc/Y0oJdjTDKXPT/buvF07XSPOv121yQ5E8nVVNjbR8nWHZC CC6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xw1VCTJ11IsZMw46QTnF+ASRcbDuGo8WQYDKOrbzOAY=; b=ySqLNk3Eo1XMry8dxrp6PjGzyTGlv0MwY8RZLT27dH4YiCnV21n6t7x7DnET0dUxnS pbYy+Bva2IhRSQZMmJINjLwJT0qYl3ZIPMcfZ7j3UjawfLsuUv0KU4pfai3HYI/Q8HyN enYBMNtyar2g0DxppHgZLpoC7YHiXhuldwPHFYv694I2jxtdpB1FHB0aP1xn8Oa+lyM3 pF94wC3S7YqHjrlOnb9bR+Q8XGJRCytKd3G8Z3MjgZp1FMgrzQ7SJnDFwdiHEKzQy+dB LQzDHECpOdtaEVxjS+5iEgJCH5jVi+kyub+0wWtJyIrc7wXKMPpgJxyv1v8sed7JjXIw lsjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U9QyLq0F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e78si4202211ote.132.2019.12.04.11.25.34; Wed, 04 Dec 2019 11:25:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U9QyLq0F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731896AbfLDSOU (ORCPT + 99 others); Wed, 4 Dec 2019 13:14:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:43506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731879AbfLDSOL (ORCPT ); Wed, 4 Dec 2019 13:14:11 -0500 Received: from localhost (unknown [217.68.49.72]) (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 B767D20865; Wed, 4 Dec 2019 18:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575483251; bh=bhPbd1Q7AtDDpN7vSxVvjBu3+BIHBLCpWA1+mEKnBJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9QyLq0Fnl3RIaEkZ17Us3Cb8Skfr8nOJO7HxHKt+RuzWUZKxiS77erKPMCiudp25 tocAtS9ZrUxE3L57LR0K0RE+Ep70f3dwkV0olSDHMlQnUVq2zs6rW4yratfEzrhAkL A1yhEDXbd1WZv6TkwP6typUf3/fOZQyUH6B/+cZw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eugen Hristev , Hans Verkuil , Mauro Carvalho Chehab , Lee Jones Subject: [PATCH 4.9 113/125] media: atmel: atmel-isc: fix asd memory allocation Date: Wed, 4 Dec 2019 18:56:58 +0100 Message-Id: <20191204175325.992756023@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175308.377746305@linuxfoundation.org> References: <20191204175308.377746305@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eugen Hristev commit 1e4e25c4959c10728fbfcc6a286f9503d32dfe02 upstream. The subsystem will free the asd memory on notifier cleanup, if the asd is added to the notifier. However the memory is freed using kfree. Thus, we cannot allocate the asd using devm_* This can lead to crashes and problems. To test this issue, just return an error at probe, but cleanup the notifier beforehand. Fixes: 106267444f ("[media] atmel-isc: add the Image Sensor Controller code") Signed-off-by: Eugen Hristev Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/atmel/atmel-isc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/media/platform/atmel/atmel-isc.c +++ b/drivers/media/platform/atmel/atmel-isc.c @@ -1297,8 +1297,11 @@ static int isc_parse_dt(struct device *d break; } - subdev_entity->asd = devm_kzalloc(dev, - sizeof(*subdev_entity->asd), GFP_KERNEL); + /* asd will be freed by the subsystem once it's added to the + * notifier list + */ + subdev_entity->asd = kzalloc(sizeof(*subdev_entity->asd), + GFP_KERNEL); if (subdev_entity->asd == NULL) { of_node_put(rem); ret = -ENOMEM; @@ -1432,6 +1435,7 @@ static int atmel_isc_probe(struct platfo &subdev_entity->notifier); if (ret) { dev_err(dev, "fail to register async notifier\n"); + kfree(subdev_entity->asd); goto cleanup_subdev; }