From patchwork Mon Mar 23 14:49:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11453185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E23A292A for ; Mon, 23 Mar 2020 14:51:04 +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 C043520786 for ; Mon, 23 Mar 2020 14:51:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="aBOHecqm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C043520786 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C04F46E1BB; Mon, 23 Mar 2020 14:50:31 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id 977836E1D7 for ; Mon, 23 Mar 2020 14:50:26 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id c187so14948604wme.1 for ; Mon, 23 Mar 2020 07:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0QSvwJkWLT9HVoZx0UnU9HwI/9xVMLUwChuDa7Qf9DI=; b=aBOHecqmh5Jv4R+kf5DJU41hDkfjVuOeQkTuBvcsE3JyoPjfRwUTYJT0xrAvP/RkWj Vu925Uq8uqoTS4G0S55FmwpappNNaTyPiES+dC6UAHn1cR8cysKfr2KGeRvb/8rducKh jKMoXUBJPbaB1ITXjJWX1bZbz/9x10gOV8Xpc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0QSvwJkWLT9HVoZx0UnU9HwI/9xVMLUwChuDa7Qf9DI=; b=R8+STKdsWPLrX/fxiO5+dKPZs8rIetAUmSmZF6BWSTr+v5Zo6JIr/0ORdgC4TKCUkt A2JoC6iKj13PBHcXiCt4LbkfPBs5RTn+Bml4ezWSrYrRGxRLkfLZnUfyNvmBXPsNkODE EAYuVR1ljW5Gb48XQCjgASzM7+VNLceopog6fwC5oK3bOxnSV1ezTxbagpW1sZPfT9gs 5QlwLDiachsLW994k4a1Nsmc87THNRuBA8x10W7WTjQ1GS4/oT+vsJpDPkMtdSLVkZIq g9zObWQ2+uwp13TEumHA/cc4beFlgAzCp1FPGVAKB0dRp1eI0thSCCzSGqymTrWclzz6 EZQQ== X-Gm-Message-State: ANhLgQ0QBlUlBw11k5n8uUdvPXKGVI/lXFKuMkG4KMcYjgB+TScuCbZ5 ncRvF4mEMIHIVqhgDznRCg+6FsggR3PnwQ== X-Google-Smtp-Source: ADFU+vsdLmkLmJDIEP2j/WmQzyvlm0i9YMeudrwF+Dt2wnTwwxz5OynDLPfGkN+N8vsKM1K3whvoZg== X-Received: by 2002:a1c:b4d4:: with SMTP id d203mr28194358wmf.85.1584975024856; Mon, 23 Mar 2020 07:50:24 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id s22sm20376522wmc.16.2020.03.23.07.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 07:50:24 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Mon, 23 Mar 2020 15:49:19 +0100 Message-Id: <20200323144950.3018436-21-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200323144950.3018436-1-daniel.vetter@ffwll.ch> References: <20200323144950.3018436-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 20/51] drm: Handle dev->unique with drmm_ X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Intel Graphics Development , Sam Ravnborg , Thomas Zimmermann , Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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. Reviewed-by: Sam Ravnborg Acked-by: Thomas Zimmermann 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 7f9d7ea543a0..c80ebc6811b1 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); @@ -1065,8 +1064,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 4a69771a4d93..c633c2ef5269 100644 --- a/drivers/gpu/drm/drm_managed.c +++ b/drivers/gpu/drm/drm_managed.c @@ -167,6 +167,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) +{ + 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_match = NULL, *dr; diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h index 7b5df7d09b19..89e6fce9f689 100644 --- a/include/drm/drm_managed.h +++ b/include/drm/drm_managed.h @@ -24,6 +24,7 @@ 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);