Skip to contentSkip to conversation

drm/amdgpu: use string choice helpers

PATCH In review R Sundar 2 participants 4 messages Oct 27, 2024 – Oct 29, 2024

Subsystems (2)
lore
Share & tools
lore

R Sundar

author
#0 lore raw

PATCH 1/1 drm/amdgpu: use string choice helpers

Use string choice helpers for better readability.

---

reported in linux repository.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c:145:8-12: opportunity for str_read_write(read)

vim +145 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c

 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c +1 -1
index 35fee3e8cde2..8cd69836dd99 100644
@@ -200,7 +200,7 @@ static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
 		dev_err_ratelimited(&i2c_adap->dev,
 				    "maddr:0x%04X size:0x%02X:quirk max_%s_len must be > %d",
 				    eeprom_addr, buf_size,
-				    read ? "read" : "write", EEPROM_OFFSET_SIZE);
+				    str_read_write(read), EEPROM_OFFSET_SIZE);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · R Sundar

Use string choice helpers for better readability.

I personally find this less readable, but if this is the preferred method going forward, I'm fine to take the patch.

Alex

Quoted 35 lines

---

reported in linux repository.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c:145:8-12: opportunity for str_read_write(read)

vim +145 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c

 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c +1 -2
index 35fee3e8cde2..8cd69836dd99 100644
@@ -200,7 +200,7 @@ static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
                dev_err_ratelimited(&i2c_adap->dev,
                                    "maddr:0x%04X size:0x%02X:quirk max_%s_len must be > %d",
                                    eeprom_addr, buf_size,
-                                   read ? "read" : "write", EEPROM_OFFSET_SIZE);
+                                   str_read_write(read), EEPROM_OFFSET_SIZE);
                return -EINVAL;
        }
 
--

2.34.1

author
#2 lore raw
Quoted 9 lines · Alex Deucher
Quoted 2 lines · R Sundar

Use string choice helpers for better readability.

I personally find this less readable, but if this is the preferred method going forward, I'm fine to take the patch.

Alex

Hi,

Thanks for the comments.

I came across this comments in string_choices.h files, where str_read_write() helpers are present.

Using these helpers offers the following benefits:

1) Reducing the hardcoding of strings, which makes the code more
elegant through these simple literal-meaning helpers.

2) Unifying the output, which prevents the same string from being
printed in various forms, such as enable/disable, enabled/disabled, en/dis.
3) Deduping by the linker, which results in a smaller binary file.

Kindly, I'm leaving the decision to maintainers.

Thanks,
Sundar

Quoted 35 lines
Quoted 35 lines

---

reported in linux repository.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c:145:8-12: opportunity for str_read_write(read)

vim +145 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c

  drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c +1 -2
index 35fee3e8cde2..8cd69836dd99 100644
@@ -200,7 +200,7 @@ static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
                 dev_err_ratelimited(&i2c_adap->dev,
                                     "maddr:0x%04X size:0x%02X:quirk max_%s_len must be > %d",
                                     eeprom_addr, buf_size,
-                                   read ? "read" : "write", EEPROM_OFFSET_SIZE);
+                                   str_read_write(read), EEPROM_OFFSET_SIZE);
                 return -EINVAL;
         }
 
--

2.34.1

#3 lore raw
Quoted 21 lines · R Sundar
Quoted 9 lines · Alex Deucher
Quoted 2 lines · R Sundar

Use string choice helpers for better readability.

I personally find this less readable, but if this is the preferred method going forward, I'm fine to take the patch.

Alex

Hi,

Thanks for the comments.

I came across this comments in string_choices.h files, where str_read_write() helpers are present.

Using these helpers offers the following benefits:

Quoted 8 lines

1) Reducing the hardcoding of strings, which makes the code more
elegant through these simple literal-meaning helpers.

2) Unifying the output, which prevents the same string from being
printed in various forms, such as enable/disable, enabled/disabled, en/dis.
3) Deduping by the linker, which results in a smaller binary file.

Thanks. I've applied it.

Alex

Quoted 41 lines

Kindly, I'm leaving the decision to maintainers.

Thanks,
Sundar

Quoted 35 lines
Quoted 35 lines

---

reported in linux repository.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c:145:8-12: opportunity for str_read_write(read)

vim +145 drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c

  drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eeprom.c +1 -2
index 35fee3e8cde2..8cd69836dd99 100644
@@ -200,7 +200,7 @@ static int amdgpu_eeprom_xfer(struct i2c_adapter *i2c_adap, u32 eeprom_addr,
                 dev_err_ratelimited(&i2c_adap->dev,
                                     "maddr:0x%04X size:0x%02X:quirk max_%s_len must be > %d",
                                     eeprom_addr, buf_size,
-                                   read ? "read" : "write", EEPROM_OFFSET_SIZE);
+                                   str_read_write(read), EEPROM_OFFSET_SIZE);
                 return -EINVAL;
         }
 
--

2.34.1