Skip to contentSkip to conversation

drm/amdkfd: Add format attribute to kfd_smi_event_add

PATCH In review Philip Yang 2 participants 2 messages Mar 4, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Add format attribute to kfd_smi_event_add

To enable compiler type-checked against the format string in callers.

All warnings (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

warning: function 'kfd_smi_event_add' might be a candidate for

'gnu_printf' format attribute [-Wsuggest-attribute=format]

Fixes 67e874c2fa ("drm/amdkfd: Add SMI add event helper")
---
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -0
index bba8d9692a4c..02b6b26ee8f3 100644
@@ -176,6 +176,7 @@ static void add_event_to_kfifo(struct kfd_dev *dev, unsigned int smi_event,
 	rcu_read_unlock();
 }
 
+__attribute__ ((format (printf, 3, 4)))
 static void kfd_smi_event_add(struct kfd_dev *dev, unsigned int event,
 			      char *fmt, ...)
 {
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 2022-03-04 um 09:48 schrieb Philip Yang:

Quoted 19 lines

To enable compiler type-checked against the format string in callers.

All warnings (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

warning: function 'kfd_smi_event_add' might be a candidate for

'gnu_printf' format attribute [-Wsuggest-attribute=format]

Fixes 67e874c2fa ("drm/amdkfd: Add SMI add event helper")
---
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
index bba8d9692a4c..02b6b26ee8f3 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c static void add_event_to_kfifo(struct kfd_dev *dev, unsigned int smi_event, · line 179

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -0
@@ -176,6 +176,7 @@ static void add_event_to_kfifo(struct kfd_dev *dev, unsigned int smi_event,
  	rcu_read_unlock();
  }
 
+__attribute__ ((format (printf, 3, 4)))

I see that there is a shortcut for this defined in include/linux/compiler_attributes.h. It's just

__printf(3, 4)

With that fixed, the patch is

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
  static void kfd_smi_event_add(struct kfd_dev *dev, unsigned int event,
  			      char *fmt, ...)
  {