Skip to contentSkip to conversation

hwmon: (occ) Replace open-coded variant of %*phN specifier

PATCH Applied Andy Shevchenko 3 participants 3 messages Jul 26, 2022 – Aug 2, 2022 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (occ) Replace open-coded variant of %*phN specifier

printf()-like functions in the kernel have extensions, such as %*phN to dump small pieces of memory as hex bytes.

Replace custom approach with the direct use of %*phN.

---
 drivers/hwmon/occ/common.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hwmon/occ/common.c +2 -6
index 157b73a3da29..45407b12db4b 100644
@@ -729,18 +729,14 @@ static ssize_t occ_show_extended(struct device *dev,
 			rc = sysfs_emit(buf, "%u",
 					get_unaligned_be32(&extn->sensor_id));
 		} else {
-			rc = sysfs_emit(buf, "%02x%02x%02x%02x\n",
-					extn->name[0], extn->name[1],
-					extn->name[2], extn->name[3]);
+			rc = sysfs_emit(buf, "%4phN\n", extn->name);
 		}
 		break;
 	case 1:
 		rc = sysfs_emit(buf, "%02x\n", extn->flags);
 		break;
 	case 2:
-		rc = sysfs_emit(buf, "%02x%02x%02x%02x%02x%02x\n",
-				extn->data[0], extn->data[1], extn->data[2],
-				extn->data[3], extn->data[4], extn->data[5]);
+		rc = sysfs_emit(buf, "%6phN\n", extn->data);
 		break;
 	default:
 		return -EINVAL;
Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Andy Shevchenko

printf()-like functions in the kernel have extensions, such as %*phN to dump small pieces of memory as hex bytes.

Replace custom approach with the direct use of %*phN.

Applied.

Thanks,
Guenter

Quoted 29 lines
---
  drivers/hwmon/occ/common.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hwmon/occ/common.c +2 -6
index 157b73a3da29..45407b12db4b 100644
@@ -729,18 +729,14 @@ static ssize_t occ_show_extended(struct device *dev,
  			rc = sysfs_emit(buf, "%u",
  					get_unaligned_be32(&extn->sensor_id));
  		} else {
-			rc = sysfs_emit(buf, "%02x%02x%02x%02x\n",
-					extn->name[0], extn->name[1],
-					extn->name[2], extn->name[3]);
+			rc = sysfs_emit(buf, "%4phN\n", extn->name);
  		}
  		break;
  	case 1:
  		rc = sysfs_emit(buf, "%02x\n", extn->flags);
  		break;
  	case 2:
-		rc = sysfs_emit(buf, "%02x%02x%02x%02x%02x%02x\n",
-				extn->data[0], extn->data[1], extn->data[2],
-				extn->data[3], extn->data[4], extn->data[5]);
+		rc = sysfs_emit(buf, "%6phN\n", extn->data);
  		break;
  	default:
  		return -EINVAL;
#2 lore raw
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Andy Shevchenko

printf()-like functions in the kernel have extensions, such as %*phN to dump small pieces of memory as hex bytes.

Replace custom approach with the direct use of %*phN.

Email was acting up so I missed this at the time. Thanks Andy!

Quoted 37 lines

Applied.

Thanks,
Guenter

Quoted 30 lines

---
  drivers/hwmon/occ/common.c | 8 ++------

  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hwmon/occ/common.c +1 -3
index 157b73a3da29..45407b12db4b 100644
@@ -729,18 +729,14 @@ static ssize_t occ_show_extended(struct device 
 *dev,
               rc = sysfs_emit(buf, "%u",
 get_unaligned_be32(&extn->sensor_id));
           } else {
-            rc = sysfs_emit(buf, "%02x%02x%02x%02x\n",
-                    extn->name[0], extn->name[1],
-                    extn->name[2], extn->name[3]);
+            rc = sysfs_emit(buf, "%4phN\n", extn->name);
           }
           break;

      case 1:
          rc = sysfs_emit(buf, "%02x\n", extn->flags); break;
      case 2:
-        rc = sysfs_emit(buf, "%02x%02x%02x%02x%02x%02x\n", -                extn->data[0], extn->data[1], extn->data[2], -                extn->data[3], extn->data[4], extn->data[5]); +        rc = sysfs_emit(buf, "%6phN\n", extn->data); break;
      default:
          return -EINVAL;