Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1447866yba; Tue, 2 Apr 2019 09:03:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzqvNH74ZgHMh2YcpjHrSGnBofj1xtXvIJSzuNTkmRcgYKxfzRP7x831cm/9foxl8BLKL1 X-Received: by 2002:a17:902:e912:: with SMTP id cs18mr71634585plb.130.1554221017861; Tue, 02 Apr 2019 09:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554221017; cv=none; d=google.com; s=arc-20160816; b=F2Cxetvmdai3svpyEfAD2XDgI3d2hGdvzRg2xdf5YW4kLKrA51g+cPL/mZghBuIX5S b1KVcpbyFWjZTKKh/8HEXWhWK2yc6Rg/nGt8I4ZehA6cnK90oeR5O3QeG7b4pmCPJoSc GRpgmFbFoAnOTGfw7D6Eg39gMwsefs3xmrgI4y+lR95R1mq3/CAgdU6GuZfq9pZxDGKx 6Etb45KDcH9cWgh+959qZaPpqrNdhLV4GegmZiDk8OVmfvXC4glY2+hC1hF+52q+RQ0r jGF/bTCI/OyXBcUQF1qtOAodanjA4TcJLdhjhUL9jOx1gd1xQmByVzxmOdAcVu4xkNbW GYSw== 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 :references:in-reply-to:date:cc:to:from:subject:message-id; bh=i43saw6ka7ir+HafqqtFbdCzRANqhJ3CkzdjsAY8Zt8=; b=Omaadk5nhA2BuMHjNY8yrSxDHra6j8CU1Yd3SnqPxd8/5OElQR+VO0ve2Mu420wF7/ U0++YJa2ZtXJQYX7Ck28589ibvpcpmpx8ANkVbhvk9BUXbpox3EdzXArww3vy5EuDpFF jHUh565JaGNKuFT73VYP8Iv0naoc44bs3AyRLeM7mB8WCRB2pLCY0UN2VNPHHpmf3jV3 LzEKxyn/bYwXYmgBEXnWAUmaIH13GzmoS/P2q3RTSXKmaoCWPH5FTrSzNF6m9jRIMgKH uphXivFEQSfB8MjqQJhzmR6S66xRqPWhvn1b2Apf0hcG9r5T+z2YoZeBUbcIKak9ssf7 1aGQ== ARC-Authentication-Results: i=1; mx.google.com; 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 g11si820968plt.35.2019.04.02.09.03.21; Tue, 02 Apr 2019 09:03:37 -0700 (PDT) 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; 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 S1731693AbfDBPt1 (ORCPT + 99 others); Tue, 2 Apr 2019 11:49:27 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:37867 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731650AbfDBPt0 (ORCPT ); Tue, 2 Apr 2019 11:49:26 -0400 Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1hBLfA-0003VL-5y; Tue, 02 Apr 2019 17:49:24 +0200 Message-ID: <1554220163.2338.2.camel@pengutronix.de> Subject: Re: [PATCH 1/3] ipuv3-crtc: add remove action for devres data From: Philipp Zabel To: Michael Grzeschik , airlied@linux.ie, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, linux@armlinux.org.uk, dri-devel@lists.freedesktop.org, rafael@kernel.org, kernel@pengutronix.de Date: Tue, 02 Apr 2019 17:49:23 +0200 In-Reply-To: <20190402134904.588-2-m.grzeschik@pengutronix.de> References: <0687f68004b28ed3a364b06a9eb64e2e@agner.ch> <20190402134904.588-1-m.grzeschik@pengutronix.de> <20190402134904.588-2-m.grzeschik@pengutronix.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:1a17 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, On Tue, 2019-04-02 at 15:49 +0200, Michael Grzeschik wrote: > The destroy function in drm_mode_config_cleanup will remove the objects > in ipu-drm-core by calling its destroy functions if the bind function > fails. The drm_crtc is also part of the devres allocated ipu_crtc > object. The ipu_crtc object will already be cleaned up if the bind for > the crtc fails. This leads drm_crtc_cleanup try to clean already freed > memory. > > We fix this issue by adding the devres action ipu_crtc_remove_head which > will remove its head from the objects in ipu-drm-core which then never > calls its destroy function anymore. > > Signed-off-by: Michael Grzeschik > --- > drivers/gpu/drm/imx/ipuv3-crtc.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c > index ec3602ebbc1cd..fa1ee33a43d77 100644 > --- a/drivers/gpu/drm/imx/ipuv3-crtc.c > +++ b/drivers/gpu/drm/imx/ipuv3-crtc.c > @@ -429,6 +429,14 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc, > return ret; > } > > +static void ipu_crtc_remove_head(void *data) > +{ > + struct ipu_crtc *ipu_crtc = data; > + struct drm_crtc *crtc = &ipu_crtc->base; > + > + list_del(&crtc->head); I don't think reaching into drm_crtc internals like this is going to be robust. Currently, this is either missing the rest of drm_crtc_cleanup, or it will crash if drm_crtc_init_with_planes hasn't been called yet. I think you could call devm_add_action with a function that calls drm_crtc_cleanup after drm_crtc_init_with_planes in ipu_crtc_init. Alternatively, the ipu_crtc allocation could be changed to kzalloc. It would then have to freed manually in the drm_crtc_funcs->destroy callback. regards Philipp