From patchwork Fri Jul 7 23:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 701201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50031C001E0 for ; Fri, 7 Jul 2023 23:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231909AbjGGXNG (ORCPT ); Fri, 7 Jul 2023 19:13:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232322AbjGGXNE (ORCPT ); Fri, 7 Jul 2023 19:13:04 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B10E2128 for ; Fri, 7 Jul 2023 16:13:03 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4fbb281eec6so3788110e87.1 for ; Fri, 07 Jul 2023 16:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688771582; x=1691363582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4JIC0i/p4L094zvKoyaFxk2BI1sJ87dC6V47KMm2pSU=; b=XlsrISZ1rXo9GVFjgob38QH50MzLo0WpGU/IhxV1j6Y5wOHMOU/hvnA71hsOCbbUdR 06Sdyr9fQoplyhwvbyVayoVWfyi6faZNLwhx1ME70aqOcAXdGGC1vls63+gbkhsQYVY1 m2eRiEuxcrMwqIVz42oezhLhnBjuIyJ3wgqgzGjIcDQmvLtWoT3CnGMDFHhYDfoJWEhh VrLDIxk4CCUlv+F1gTbTiUS9ayaoatELjpQDzxsEd3F+HggqFegHqGJStTRzLd3IC5VD SyXXULhAlke05jHav0QVp71WGuEhM9QRyyQ9Xu8xOHlf/4E6Dv/6Y0VYwCGipk0x6CC7 sOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688771582; x=1691363582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4JIC0i/p4L094zvKoyaFxk2BI1sJ87dC6V47KMm2pSU=; b=lUCLBsc1RImiLSIeTlO/0wHH57w3yzbDrmurnv5ERuCeul3al1Bs26Wh2Oz5XcfKp5 X71EYgkD124n5NZqh7MqFvt8WctFyD+Dx4TDvuj3pACVgqjdKI8cMKISkiYPRBJBtxWp GZZccq3qQCvnp3adRt3K1FitItPxt500e8V6o/r6z6krOc7zfitJ9wXv7lTrWDXyMEv6 8U8xx4cBSqL4pD6fGkstOhDnB5WVIjl7f9na1Glz1/C6YKZ1sahOX3dbEDoagptz84Ea WnHhb/Jafkwii4DoywzmqMRBiDTWIyJxruviUbBWg3V+3+LQwDfG9YInqaVDlvUZdjVf 0e5A== X-Gm-Message-State: ABy/qLa3RtwvDx+XZZ59UdZrtMFssfDjE9smytlEzTwxdqJdWsnmlXhT JzZ6O6fsp5NBfea+x30r5yLK8w== X-Google-Smtp-Source: APBJJlHkVpi9RAJ3AFvinqdVZLJYrTnWcpx/Dr3VWF6Elt1N+pbECnp8x2+Dxe7xBra+5UxmkaitnQ== X-Received: by 2002:a19:5e55:0:b0:4fb:78a0:dd34 with SMTP id z21-20020a195e55000000b004fb78a0dd34mr4569573lfi.42.1688771581844; Fri, 07 Jul 2023 16:13:01 -0700 (PDT) Received: from umbar.unikie.fi ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id d1-20020ac25441000000b004fb7388360esm841643lfn.188.2023.07.07.16.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 16:13:01 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar , Marijn Suijten Cc: Stephen Boyd , David Airlie , Daniel Vetter , Bjorn Andersson , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [PATCH v2 13/13] drm/msm/dpu: use drmm-managed allocation for dpu_encoder_virt Date: Sat, 8 Jul 2023 02:12:51 +0300 Message-Id: <20230707231251.3849701-14-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707231251.3849701-1-dmitry.baryshkov@linaro.org> References: <20230707231251.3849701-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org It is incorrect to use devm-managed memory allocations for DRM data structures exposed to userspace. They should use drmm_ allocations. Change struct dpu_encoder allocation to use drmm_encoder_alloc(). This removes the need to perform any actions on encoder destruction. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 50 +++++---------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c index b42176ce4a3a..65c6c863f7c6 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c @@ -443,23 +443,6 @@ int dpu_encoder_get_linecount(struct drm_encoder *drm_enc) return linecount; } -static void dpu_encoder_destroy(struct drm_encoder *drm_enc) -{ - struct dpu_encoder_virt *dpu_enc = NULL; - int i = 0; - - if (!drm_enc) { - DPU_ERROR("invalid encoder\n"); - return; - } - - dpu_enc = to_dpu_encoder_virt(drm_enc); - DPU_DEBUG_ENC(dpu_enc, "\n"); - - drm_encoder_cleanup(drm_enc); - mutex_destroy(&dpu_enc->enc_lock); -} - void dpu_encoder_helper_split_config( struct dpu_encoder_phys *phys_enc, enum dpu_intf interface) @@ -2365,7 +2348,6 @@ static const struct drm_encoder_helper_funcs dpu_encoder_helper_funcs = { }; static const struct drm_encoder_funcs dpu_encoder_funcs = { - .destroy = dpu_encoder_destroy, .late_register = dpu_encoder_late_register, .early_unregister = dpu_encoder_early_unregister, }; @@ -2376,20 +2358,13 @@ struct drm_encoder *dpu_encoder_init(struct drm_device *dev, { struct msm_drm_private *priv = dev->dev_private; struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms); - struct drm_encoder *drm_enc = NULL; - struct dpu_encoder_virt *dpu_enc = NULL; - int ret = 0; + struct dpu_encoder_virt *dpu_enc; + int ret; - dpu_enc = devm_kzalloc(dev->dev, sizeof(*dpu_enc), GFP_KERNEL); - if (!dpu_enc) - return ERR_PTR(-ENOMEM); - - ret = drm_encoder_init(dev, &dpu_enc->base, &dpu_encoder_funcs, - drm_enc_mode, NULL); - if (ret) { - devm_kfree(dev->dev, dpu_enc); - return ERR_PTR(ret); - } + dpu_enc = drmm_encoder_alloc(dev, struct dpu_encoder_virt, base, + &dpu_encoder_funcs, drm_enc_mode, NULL); + if (IS_ERR(dpu_enc)) + return ERR_CAST(dpu_enc); drm_encoder_helper_add(&dpu_enc->base, &dpu_encoder_helper_funcs); @@ -2399,8 +2374,10 @@ struct drm_encoder *dpu_encoder_init(struct drm_device *dev, mutex_init(&dpu_enc->rc_lock); ret = dpu_encoder_setup_display(dpu_enc, dpu_kms, disp_info); - if (ret) - goto fail; + if (ret) { + DPU_ERROR("failed to setup encoder\n"); + return ERR_PTR(-ENOMEM); + } atomic_set(&dpu_enc->frame_done_timeout_ms, 0); timer_setup(&dpu_enc->frame_done_timer, @@ -2426,13 +2403,6 @@ struct drm_encoder *dpu_encoder_init(struct drm_device *dev, DPU_DEBUG_ENC(dpu_enc, "created\n"); return &dpu_enc->base; - -fail: - DPU_ERROR("failed to create encoder\n"); - if (drm_enc) - dpu_encoder_destroy(drm_enc); - - return ERR_PTR(ret); } int dpu_encoder_wait_for_event(struct drm_encoder *drm_enc,