From: Jani Nikula <jani.nikula@intel.com>
To: Gustavo Sousa <gustavo.sousa@intel.com>,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 05/10] drm/i915 & drm/xe: save struct drm_device to drvdata
Date: Fri, 02 Aug 2024 11:18:39 +0300 [thread overview]
Message-ID: <8734nn72xs.fsf@intel.com> (raw)
In-Reply-To: <172253392110.5121.3280125155104128634@gjsousa-mobl2>
On Thu, 01 Aug 2024, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> Quoting Jani Nikula (2024-07-29 11:30:06-03:00)
>>In the future, the display code shall not have any idea about struct
>>xe_device or struct drm_i915_private, but will need to get at the struct
>>drm_device via drvdata. Store the struct drm_device pointer to drvdata
>>instead of the driver specific pointer.
>>
>>Even though struct drm_device is embedded in both struct xe_device and
>>struct drm_i915_private at offset 0, take care to check for NULL before
>>using container_of() to allow for other offsets.
>
> I think the second half of this paragraph could be rephrased. One might
> think that the text is suggesting that checking for NULL has something
> to do with allowing other offsets.
>
> I would jump directly to mention using container_of() and would assume
> that it is implied that NULL check is necessary before using it. :-)
But I *am* suggesting the NULL check before container_of() has
everything to do with allowing other offsets!
container_of() will return a NULL pointer for a NULL pointer when the
offset is 0, but will return a negative garbage pointer otherwise.
BR,
Jani.
>
> Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com>
>
>>
>>Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>>---
>> drivers/gpu/drm/i915/i915_driver.c | 2 +-
>> drivers/gpu/drm/i915/i915_drv.h | 8 ++++++--
>> drivers/gpu/drm/i915/selftests/mock_gem_device.c | 2 +-
>> drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h | 4 +++-
>> drivers/gpu/drm/xe/xe_device.h | 8 ++++++--
>> drivers/gpu/drm/xe/xe_pci.c | 2 +-
>> 6 files changed, 18 insertions(+), 8 deletions(-)
>>
>>diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
>>index fb8e9c2fcea5..176c13c2e191 100644
>>--- a/drivers/gpu/drm/i915/i915_driver.c
>>+++ b/drivers/gpu/drm/i915/i915_driver.c
>>@@ -723,7 +723,7 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
>> if (IS_ERR(i915))
>> return i915;
>>
>>- pci_set_drvdata(pdev, i915);
>>+ pci_set_drvdata(pdev, &i915->drm);
>>
>> /* Device parameters start as a copy of module parameters. */
>> i915_params_copy(&i915->params, &i915_modparams);
>>diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
>>index d7723dd11c80..f6edaef73db5 100644
>>--- a/drivers/gpu/drm/i915/i915_drv.h
>>+++ b/drivers/gpu/drm/i915/i915_drv.h
>>@@ -365,12 +365,16 @@ static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
>>
>> static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
>> {
>>- return dev_get_drvdata(kdev);
>>+ struct drm_device *drm = dev_get_drvdata(kdev);
>>+
>>+ return drm ? to_i915(drm) : NULL;
>> }
>>
>> static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
>> {
>>- return pci_get_drvdata(pdev);
>>+ struct drm_device *drm = pci_get_drvdata(pdev);
>>+
>>+ return drm ? to_i915(drm) : NULL;
>> }
>>
>> static inline struct intel_gt *to_gt(const struct drm_i915_private *i915)
>>diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>index 0bd29846873b..91794ca17a58 100644
>>--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>@@ -172,7 +172,7 @@ struct drm_i915_private *mock_gem_device(void)
>> return NULL;
>> }
>>
>>- pci_set_drvdata(pdev, i915);
>>+ pci_set_drvdata(pdev, &i915->drm);
>>
>> /* Device parameters start as a copy of module parameters. */
>> i915_params_copy(&i915->params, &i915_modparams);
>>diff --git a/drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h b/drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h
>>index 2feedddf1e40..766fba88a3c8 100644
>>--- a/drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h
>>+++ b/drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h
>>@@ -23,7 +23,9 @@ static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
>>
>> static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
>> {
>>- return dev_get_drvdata(kdev);
>>+ struct drm_device *drm = dev_get_drvdata(kdev);
>>+
>>+ return drm ? to_i915(drm) : NULL;
>> }
>>
>> #define IS_PLATFORM(xe, x) ((xe)->info.platform == x)
>>diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
>>index 2c96f1b2aafd..022876eebfd5 100644
>>--- a/drivers/gpu/drm/xe/xe_device.h
>>+++ b/drivers/gpu/drm/xe/xe_device.h
>>@@ -17,12 +17,16 @@ static inline struct xe_device *to_xe_device(const struct drm_device *dev)
>>
>> static inline struct xe_device *kdev_to_xe_device(struct device *kdev)
>> {
>>- return dev_get_drvdata(kdev);
>>+ struct drm_device *drm = dev_get_drvdata(kdev);
>>+
>>+ return drm ? to_xe_device(drm) : NULL;
>> }
>>
>> static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev)
>> {
>>- return pci_get_drvdata(pdev);
>>+ struct drm_device *drm = pci_get_drvdata(pdev);
>>+
>>+ return drm ? to_xe_device(drm) : NULL;
>> }
>>
>> static inline struct xe_device *xe_device_const_cast(const struct xe_device *xe)
>>diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
>>index 7bb811b4a057..f861b8cf931a 100644
>>--- a/drivers/gpu/drm/xe/xe_pci.c
>>+++ b/drivers/gpu/drm/xe/xe_pci.c
>>@@ -800,7 +800,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>> if (IS_ERR(xe))
>> return PTR_ERR(xe);
>>
>>- pci_set_drvdata(pdev, xe);
>>+ pci_set_drvdata(pdev, &xe->drm);
>>
>> xe_pm_assert_unbounded_bridge(xe);
>> subplatform_desc = find_subplatform(xe, desc);
>>--
>>2.39.2
>>
--
Jani Nikula, Intel
next prev parent reply other threads:[~2024-08-02 8:19 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 14:30 [PATCH 00/10] drm/xe & drm/i915: drvdata usage changes Jani Nikula
2024-07-29 14:30 ` [PATCH 01/10] drm/xe: use pdev_to_xe_device() instead of pci_get_drvdata() directly Jani Nikula
2024-08-01 16:31 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 02/10] drm/xe: add kdev_to_xe_device() helper and use it Jani Nikula
2024-08-01 16:41 ` Gustavo Sousa
2024-08-06 12:10 ` Jani Nikula
2024-07-29 14:30 ` [PATCH 03/10] drm/xe/tests: fix drvdata usage Jani Nikula
2024-08-01 16:57 ` Gustavo Sousa
2024-08-06 12:13 ` Jani Nikula
2024-08-06 12:14 ` Jani Nikula
2024-08-07 16:52 ` Lucas De Marchi
2024-07-29 14:30 ` [PATCH 04/10] drm/i915: use pdev_to_i915() instead of pci_get_drvdata() directly Jani Nikula
2024-08-01 17:03 ` Gustavo Sousa
2024-08-01 17:27 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 05/10] drm/i915 & drm/xe: save struct drm_device to drvdata Jani Nikula
2024-08-01 17:38 ` Gustavo Sousa
2024-08-02 8:18 ` Jani Nikula [this message]
2024-08-02 12:08 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 06/10] drm/i915: support struct device and pci_dev in to_intel_display() Jani Nikula
2024-08-01 17:46 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 07/10] drm/i915/audio: migrate away from kdev_to_i915() Jani Nikula
2024-08-01 18:03 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 08/10] drm/i915/hdcp: migrate away from kdev_to_i915() in bind/unbind Jani Nikula
2024-08-01 18:03 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 09/10] drm/i915/hdcp: migrate away from kdev_to_i915() in GSC messaging Jani Nikula
2024-08-01 18:09 ` Gustavo Sousa
2024-08-06 14:03 ` Jani Nikula
2024-08-06 14:14 ` Jani Nikula
2024-08-07 19:03 ` Gustavo Sousa
2024-07-29 14:30 ` [PATCH 10/10] drm/xe/display: remove unused compat kdev_to_i915() and pdev_to_i915() Jani Nikula
2024-08-01 18:11 ` Gustavo Sousa
2024-07-29 15:20 ` ✗ Fi.CI.SPARSE: warning for drm/xe & drm/i915: drvdata usage changes Patchwork
2024-07-29 15:46 ` ✗ Fi.CI.BAT: failure " Patchwork
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=8734nn72xs.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=gustavo.sousa@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.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).