linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Tian Tao <tiantao6@hisilicon.com>,
	airlied@linux.ie, daniel@ffwll.ch, kraxel@redhat.com,
	alexander.deucher@amd.com, tglx@linutronix.de,
	dri-devel@lists.freedesktop.org, xinliang.liu@linaro.org,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv
Date: Thu, 26 Nov 2020 14:13:23 +0100	[thread overview]
Message-ID: <b70700a0-5278-3fd9-b333-baabb6d3010b@suse.de> (raw)
In-Reply-To: <e7ae66dc-6bfe-0413-687a-55f4f392f0fd@suse.de>


[-- Attachment #1.1.1: Type: text/plain, Size: 9984 bytes --]

Hi

Am 26.11.20 um 14:05 schrieb Thomas Zimmermann:
> Hi
> 
> Am 26.11.20 um 13:02 schrieb Tian Tao:
>> Use the devm_drm_dev_alloc provided by the drm framework to alloc
>> a struct hibmc_drm_private.
>>
>> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
>> ---
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c   |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  | 51 
>> +++++++++++-------------
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c      |  8 ++--
>>   5 files changed, 31 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> index ea962ac..096eea9 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs 
>> hibmc_crtc_helper_funcs = {
>>   int hibmc_de_init(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct drm_crtc *crtc = &priv->crtc;
>>       struct drm_plane *plane = &priv->primary_plane;
>>       int ret;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> index d845657..ea3d81b 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> @@ -80,30 +80,31 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>   static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>   {
>>       int ret;
>> +    struct drm_device *dev = &priv->dev;
> 
> I think that's good style. Pointers deserve their own local variable if 
> they are used multiple times within a function. I would move this change 
> into a separate patch, because it's only semi-related to the actual 
> changes.
> 
>> -    drm_mode_config_init(priv->dev);
>> +    drm_mode_config_init(dev);
>>       priv->mode_config_initialized = true;
>> -    priv->dev->mode_config.min_width = 0;
>> -    priv->dev->mode_config.min_height = 0;
>> -    priv->dev->mode_config.max_width = 1920;
>> -    priv->dev->mode_config.max_height = 1200;
>> +    dev->mode_config.min_width = 0;
>> +    dev->mode_config.min_height = 0;
>> +    dev->mode_config.max_width = 1920;
>> +    dev->mode_config.max_height = 1200;
>> -    priv->dev->mode_config.fb_base = priv->fb_base;
>> -    priv->dev->mode_config.preferred_depth = 32;
>> -    priv->dev->mode_config.prefer_shadow = 1;
>> +    dev->mode_config.fb_base = priv->fb_base;
>> +    dev->mode_config.preferred_depth = 32;
>> +    dev->mode_config.prefer_shadow = 1;
>> -    priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>> +    dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>       ret = hibmc_de_init(priv);
>>       if (ret) {
>> -        drm_err(priv->dev, "failed to init de: %d\n", ret);
>> +        drm_err(dev, "failed to init de: %d\n", ret);
>>           return ret;
>>       }
>>       ret = hibmc_vdac_init(priv);
>>       if (ret) {
>> -        drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>> +        drm_err(dev, "failed to init vdac: %d\n", ret);
>>           return ret;
>>       }
>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private 
>> *priv)
>>   static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>   {
>>       if (priv->mode_config_initialized) {
>> -        drm_mode_config_cleanup(priv->dev);
>> +        drm_mode_config_cleanup(&priv->dev);
>>           priv->mode_config_initialized = false;
>>       }
>>   }
>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct 
>> hibmc_drm_private *priv)
>>   static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct pci_dev *pdev = dev->pdev;
>>       resource_size_t addr, size, ioaddr, iosize;
>> @@ -258,17 +259,9 @@ static int hibmc_unload(struct drm_device *dev)
>>   static int hibmc_load(struct drm_device *dev)
>>   {
>> -    struct hibmc_drm_private *priv;
>> +    struct hibmc_drm_private *priv = dev->dev_private;
> 
> Please use to_hibmc_drm_private() instead. dev_private is deprecated.
> 
>>       int ret;
>> -    priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> -    if (!priv) {
>> -        drm_err(dev, "no memory to allocate for hibmc_drm_private\n");
>> -        return -ENOMEM;
>> -    }
>> -    dev->dev_private = priv;
>> -    priv->dev = dev;
>> -
>>       ret = hibmc_hw_init(priv);
>>       if (ret)
>>           goto err;
>> @@ -310,6 +303,7 @@ static int hibmc_load(struct drm_device *dev)
>>   static int hibmc_pci_probe(struct pci_dev *pdev,
>>                  const struct pci_device_id *ent)
>>   {
>> +    struct hibmc_drm_private *priv;
>>       struct drm_device *dev;
>>       int ret;
>> @@ -318,19 +312,22 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>>       if (ret)
>>           return ret;
>> -    dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
>> -    if (IS_ERR(dev)) {
>> +    priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
>> +                  struct hibmc_drm_private, dev);
>> +    if (IS_ERR(priv)) {
>>           DRM_ERROR("failed to allocate drm_device\n");
>> -        return PTR_ERR(dev);
>> +        return PTR_ERR(priv);
>>       }
>> +    dev = &priv->dev;
>> +    dev->dev_private = priv;
> 
> Don't do this assignment. After this patch, no code in hibmc should 
> touch dev_private. Instead, change to_hibmc_drm_private() to upcast from 
> dev. As in [1].

[1] was supposed to be

 
https://elixir.bootlin.com/linux/v5.9.11/source/drivers/gpu/drm/mgag200/mgag200_drv.h#L177

Best regards
Thomas

> 
>>       dev->pdev = pdev;
>>       pci_set_drvdata(pdev, dev);
>>       ret = pci_enable_device(pdev);
>>       if (ret) {
>>           drm_err(dev, "failed to enable pci device: %d\n", ret);
>> -        goto err_free;
>> +        return ret;
>>       }
>>       ret = hibmc_load(dev);
>> @@ -354,8 +351,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>>       hibmc_unload(dev);
>>   err_disable:
>>       pci_disable_device(pdev);
>> -err_free:
>> -    drm_dev_put(dev);
>>       return ret;
>>   }
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> index f310a83..e35353a 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>       resource_size_t  fb_size;
>>       /* drm */
>> -    struct drm_device  *dev;
>> +    struct drm_device dev;
>>       struct drm_plane primary_plane;
>>       struct drm_crtc crtc;
>>       struct drm_encoder encoder;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> index 74e26c2..d35548d 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs 
>> hibmc_encoder_funcs = {
>>   int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct hibmc_connector *hibmc_connector = &priv->connector;
>>       struct drm_encoder *encoder = &priv->encoder;
>>       struct drm_connector *connector = &hibmc_connector->base;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> index 602ece1..e84fb81 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>   {
>>       struct drm_vram_mm *vmm;
>>       int ret;
>> -    struct drm_device *dev = hibmc->dev;
>> +    struct drm_device *dev = &hibmc->dev;
>>       vmm = drm_vram_helper_alloc_mm(dev,
>>                          pci_resource_start(dev->pdev, 0),
>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>   void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>   {
>> -    if (!hibmc->dev->vram_mm)
>> +    struct drm_device *dev = &hibmc->dev;
>> +
>> +    if (!dev->vram_mm)
>>           return;
>> -    drm_vram_helper_release_mm(hibmc->dev);
>> +    drm_vram_helper_release_mm(dev);
> 
> That's OK for now. A good follow-up patchset is the conversion to 
> managed DRM helpers. We have these for modesetting, vram helpers and 
> others.
> 
>>   }
>>   int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>
> 
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

[-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --]
[-- Type: application/pgp-keys, Size: 8003 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  reply	other threads:[~2020-11-26 13:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 12:02 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
2020-11-26 13:05   ` Thomas Zimmermann
2020-11-26 13:13     ` Thomas Zimmermann [this message]
2020-11-26 12:02 ` [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq Tian Tao
2020-11-26 13:12   ` Thomas Zimmermann
2020-11-26 12:02 ` [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install Tian Tao
2020-11-26 13:15   ` Thomas Zimmermann
2020-12-02  8:47 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
2020-12-02  8:47 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
2020-12-02  9:02   ` Thomas Zimmermann
2020-12-02  9:27     ` tiantao (H)
2020-12-21 22:03     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b70700a0-5278-3fd9-b333-baabb6d3010b@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tiantao6@hisilicon.com \
    --cc=xinliang.liu@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).