From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3270AC34050 for ; Wed, 19 Feb 2020 14:28:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0304324654 for ; Wed, 19 Feb 2020 14:28:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HNVoEJTx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0304324654 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 967776EBFC; Wed, 19 Feb 2020 14:28:28 +0000 (UTC) Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id EF0EA8947A; Wed, 19 Feb 2020 14:28:26 +0000 (UTC) Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D2DC2F9; Wed, 19 Feb 2020 15:28:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582122505; bh=4z+CTGmqSituyCLJdy3NAd3tapKkeT1S/Em5Zl3+xuo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HNVoEJTx04+RGNXpHgaxZZC/NjxQRcF409uzA98auuuv2LUFgCDGv49dZVeN5rEj/ t8mTnnDFt0/gyQNeUg2YBG11podl2TYKTn9jqzCIlvetXSUvTUsupi6T5wcJQgnwDG iAM/CQqILAP9aoF5NKJ0WySNk1+W0gQAK8I0bozw= Date: Wed, 19 Feb 2020 16:28:06 +0200 From: Laurent Pinchart To: Daniel Vetter Subject: Re: [PATCH 21/52] drm: Handle dev->unique with drmm_ Message-ID: <20200219142806.GL5070@pendragon.ideasonboard.com> References: <20200219102122.1607365-1-daniel.vetter@ffwll.ch> <20200219102122.1607365-22-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200219102122.1607365-22-daniel.vetter@ffwll.ch> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Intel Graphics Development , DRI Development Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Daniel, Thank you for the patch. On Wed, Feb 19, 2020 at 11:20:51AM +0100, Daniel Vetter wrote: > We need to add a drmm_kstrdup for this, but let's start somewhere. > > This is not exactly perfect onion unwinding, but it's jsut a kfree so > doesn't really matter at all. > > Signed-off-by: Daniel Vetter > --- > drivers/gpu/drm/drm_drv.c | 5 ++--- > drivers/gpu/drm/drm_managed.c | 16 ++++++++++++++++ > include/drm/drm_managed.h | 1 + > 3 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index 1ee606b4a4f9..782fd5d6f8b2 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -777,7 +777,6 @@ void drm_dev_fini(struct drm_device *dev) > mutex_destroy(&dev->filelist_mutex); > mutex_destroy(&dev->struct_mutex); > drm_legacy_destroy_members(dev); > - kfree(dev->unique); > } > EXPORT_SYMBOL(drm_dev_fini); > > @@ -1063,8 +1062,8 @@ EXPORT_SYMBOL(drm_dev_unregister); > */ > int drm_dev_set_unique(struct drm_device *dev, const char *name) > { > - kfree(dev->unique); > - dev->unique = kstrdup(name, GFP_KERNEL); > + drmm_kfree(dev, dev->unique); > + dev->unique = drmm_kstrdup(dev, name, GFP_KERNEL); > > return dev->unique ? 0 : -ENOMEM; > } > diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c > index ee7c7253af61..d8a484e19830 100644 > --- a/drivers/gpu/drm/drm_managed.c > +++ b/drivers/gpu/drm/drm_managed.c > @@ -147,6 +147,22 @@ void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp) > } > EXPORT_SYMBOL(drmm_kmalloc); > > +char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp) Do we need support for gfp_t other than GFP_KERNEL ? Given that the memory will be released when the drm_device is destroyed, GFP_ATOMIC would seem of dubious use to me, and we may want to not make it possible to use it. > +{ > + size_t size; > + char *buf; > + > + if (!s) > + return NULL; > + > + size = strlen(s) + 1; > + buf = drmm_kmalloc(dev, size, gfp); > + if (buf) > + memcpy(buf, s, size); > + return buf; > +} > +EXPORT_SYMBOL_GPL(drmm_kstrdup); > + > void drmm_kfree(struct drm_device *dev, void *data) > { > struct drmres *dr = NULL, *tmp; > diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h > index 75f2c8932c69..240edd395e88 100644 > --- a/include/drm/drm_managed.h > +++ b/include/drm/drm_managed.h > @@ -21,5 +21,6 @@ static inline void *drmm_kzalloc(struct drm_device *dev, size_t size, gfp_t gfp) > { > return drmm_kmalloc(dev, size, gfp | __GFP_ZERO); > } > +char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp); > > void drmm_kfree(struct drm_device *dev, void *data); -- Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel