[PATCH v2 1/7] drm/xe: Introduce const cast helper

Michal Wajdeczko michal.wajdeczko at intel.com
Wed Jul 17 21:38:32 UTC 2024



On 17.07.2024 22:07, Cavitt, Jonathan wrote:
> -----Original Message-----
> From: Intel-xe <intel-xe-bounces at lists.freedesktop.org> On Behalf Of Michal Wajdeczko
> Sent: Wednesday, July 17, 2024 12:52 PM
> To: intel-xe at lists.freedesktop.org
> Cc: Wajdeczko, Michal <Michal.Wajdeczko at intel.com>
> Subject: [PATCH v2 1/7] drm/xe: Introduce const cast helper
>>
>> Typically we want to preserve pointer constness when converting
>> from one xe pointer to another, but in some rare cases, like kunit
>> parameter conversions, we might want to discard this constness.
>> Add a helper that we will use to clearly indicate our intention.
>>
>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
>> ---
>>  drivers/gpu/drm/xe/xe_device.h | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
>> index 0a2a3e7fd402..c2b1f9f066bd 100644
>> --- a/drivers/gpu/drm/xe/xe_device.h
>> +++ b/drivers/gpu/drm/xe/xe_device.h
>> @@ -20,6 +20,11 @@ static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev)
>>  	return pci_get_drvdata(pdev);
>>  }
>>  
>> +static inline struct xe_device *xe_device_const_cast(const struct xe_device *xe)
>> +{
>> +	return pdev_to_xe_device(to_pci_dev(xe->drm.dev));
>> +}
> 
> This function is used in the next patch and no others.  It may or may not be
> better to have this patch and the next squashed together, since that's where
> this function is used, but I can see the argument go either way.

This _other_ argument was that this helper is not strictly designed for
explicit use by those new kunit helpers, or it can be implemented in a
different way, so IMO it deserved standalone patch in a series where it
was actually used for the first time.

> 
> Just something to consider.  Not blocking.
> 
> Reviewed-by: Jonathan Cavitt <jonathan.cavitt at intel.com>
> -Jonathan Cavitt

Thanks!

> 
>> +
>>  static inline struct xe_device *ttm_to_xe_device(struct ttm_device *ttm)
>>  {
>>  	return container_of(ttm, struct xe_device, ttm);
>> -- 
>> 2.43.0
>>
>>


More information about the Intel-xe mailing list