Skip to contentSkip to conversation

HID: core: Add hid printk_once macros

PATCH In review [email protected] 2 participants 13 messages Jul 22, 2019 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 HID: core: Add hid printk_once macros

From: Joshua Clayton <[email protected]>

Make available printk_once variants to hid_warn() etc

---
 include/linux/hid.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/linux/hid.h +19 -0
index d770ab1a0479..5b239712c902 100644
@@ -1179,4 +1179,23 @@ do {									\
 #define hid_dbg(hid, fmt, arg...)			\
 	dev_dbg(&(hid)->dev, fmt, ##arg)
 
+#define hid_level_once(level, hid, fmt, arg...)		\
+	dev_level_once(level, &(hid)->dev, fmt, ##arg)
+#define hid_emerg_once(hid, fmt, arg...)		\
+	dev_emerg_once(&(hid)->dev, fmt, ##arg)
+#define hid_crit_once(hid, fmt, arg...)			\
+	dev_crit_once(&(hid)->dev, fmt, ##arg)
+#define hid_alert_once(hid, fmt, arg...)		\
+	dev_alert_once(&(hid)->dev, fmt, ##arg)
+#define hid_err_once(hid, fmt, arg...)			\
+	dev_err_once(&(hid)->dev, fmt, ##arg)
+#define hid_notice_once(hid, fmt, arg...)		\
+	dev_notice_once(&(hid)->dev, fmt, ##arg)
+#define hid_warn_once(hid, fmt, arg...)			\
+	dev_warn_once(&(hid)->dev, fmt, ##arg)
+#define hid_info_once(hid, fmt, arg...)			\
+	dev_info_once(&(hid)->dev, fmt, ##arg)
+#define hid_dbg_once(hid, fmt, arg...)			\
+	dev_dbg_once(&(hid)->dev, fmt, ##arg)
+
 #endif
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/2 HID: core: only warn once of oversize hid report

From: Joshua Clayton <[email protected]>

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all other kernel logs Protect dmesg by printing the warning only one time.

---
 drivers/hid/hid-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
index 210b81a56e1a..7afd0422b280 100644
@@ -1311,7 +1311,7 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
 			unsigned offset, unsigned n)
 {
 	if (n > 32) {
-		hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
+		hid_warn_once(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
 			 n, current->comm);
 		n = 32;
 	}
Signature · 1 line
2.21.0
#12 lore raw
In reply to [email protected]
Quoted 5 lines · On Mon, 2019-07-22 at 10:36 -0600, [email protected] wrote:

From: Joshua Clayton <[email protected]>

Make available printk_once variants to hid_warn() etc

This seems OK, but I suggest a slightly different style:

include/linux/hid.h

Quoted 1 line
include/linux/hid.h +0 -0

[]

include/linux/hid.h do { \ · line 1183

Quoted 6 lines
include/linux/hid.h +2 -0
@@ -1179,4 +1179,23 @@ do {									\
 #define hid_dbg(hid, fmt, arg...)			\
 	dev_dbg(&(hid)->dev, fmt, ##arg)
 
+#define hid_level_once(level, hid, fmt, arg...)		\
+	dev_level_once(level, &(hid)->dev, fmt, ##arg)

This one is probably not useful in actual code.

include/linux/hid.h do { \ · line 1185

Quoted 2 lines
include/linux/hid.h +2 -0
+#define hid_emerg_once(hid, fmt, arg...)		\
+	dev_emerg_once(&(hid)->dev, fmt, ##arg)

Even though I introduced those macros originally,
it's now a more common style to use:

#define hid_emerg_once(hid, fmt, ...)				\
	dev_emerg_once(&(hid)->dev, fmt, ##__VA_ARGS__)

etc...

And trivially:

hid_printk, hid_emerg, hid_crit, and hid_alert aren't used at all and could all be removed.

I'm not sure there is a use case for any of them.

Perhaps:

---
 include/linux/hid.h | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
include/linux/hid.h +21 -18
index d770ab1a0479..5d2c4b63954f 100644
@@ -1160,23 +1160,26 @@ do {									\
 		printk(KERN_DEBUG "%s: " format, __FILE__, ##arg);	\
 } while (0)
 
-#define hid_printk(level, hid, fmt, arg...)		\
-	dev_printk(level, &(hid)->dev, fmt, ##arg)
-#define hid_emerg(hid, fmt, arg...)			\
-	dev_emerg(&(hid)->dev, fmt, ##arg)
-#define hid_crit(hid, fmt, arg...)			\
-	dev_crit(&(hid)->dev, fmt, ##arg)
-#define hid_alert(hid, fmt, arg...)			\
-	dev_alert(&(hid)->dev, fmt, ##arg)
-#define hid_err(hid, fmt, arg...)			\
-	dev_err(&(hid)->dev, fmt, ##arg)
-#define hid_notice(hid, fmt, arg...)			\
-	dev_notice(&(hid)->dev, fmt, ##arg)
-#define hid_warn(hid, fmt, arg...)			\
-	dev_warn(&(hid)->dev, fmt, ##arg)
-#define hid_info(hid, fmt, arg...)			\
-	dev_info(&(hid)->dev, fmt, ##arg)
-#define hid_dbg(hid, fmt, arg...)			\
-	dev_dbg(&(hid)->dev, fmt, ##arg)
+#define hid_err(hid, fmt, ...)						\
+	dev_err(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice(hid, fmt, ...)					\
+	dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn(hid, fmt, ...)						\
+	dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info(hid, fmt, ...)						\
+	dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg(hid, fmt, ...)						\
+	dev_dbg(&(hid)->dev, fmt, ##__VA_ARGS__)
+
+#define hid_err_once(hid, fmt, ...)					\
+	dev_err_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice_once(hid, fmt, ...)					\
+	dev_notice_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn_once(hid, fmt, ...)					\
+	dev_warn_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info_once(hid, fmt, ...)					\
+	dev_info_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg_once(hid, fmt, ...)					\
+	dev_dbg_once(&(hid)->dev, fmt, ##__VA_ARGS__)
 
 #endif
#2 lore raw

Re: [PATCH 2/2] HID: core: only warn once of oversize hid report

In reply to [email protected]
Quoted 4 lines · On Mon, 2019-07-22 at 10:36 -0600, [email protected] wrote:

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all other kernel logs Protect dmesg by printing the warning only one time.

[]

drivers/hid/hid-core.c

Quoted 1 line
drivers/hid/hid-core.c +0 -0

[]

drivers/hid/hid-core.c u32 hid_field_extract(const struct hid_device *hid, u8 *report, · line 1317

Quoted 9 lines
drivers/hid/hid-core.c +1 -1
@@ -1311,7 +1311,7 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
 			unsigned offset, unsigned n)
 {
 	if (n > 32) {
-		hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
+		hid_warn_once(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
 			 n, current->comm);
 		n = 32;
 	}

Is this papering over an actual defect somewhere else? Trivially, this could use "%s: ...", __func__, ...

#3 lore raw

Re: [PATCH 2/2] HID: core: only warn once of oversize hid report

Quoted 9 lines · Joe Perches
Quoted 4 lines · On Mon, 2019-07-22 at 10:36 -0600, [email protected] wrote:

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all other kernel logs Protect dmesg by printing the warning only one time.

[]

drivers/hid/hid-core.c

Quoted 1 line
drivers/hid/hid-core.c +0 -0

[]

Quoted 11 lines

drivers/hid/hid-core.c u32 hid_field_extract(const struct hid_device *hid, u8 *report, · line 1317

Quoted 9 lines
drivers/hid/hid-core.c +1 -1
@@ -1311,7 +1311,7 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
                      unsigned offset, unsigned n)
 {
      if (n > 32) {
-             hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
+             hid_warn_once(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
                       n, current->comm);
              n = 32;
      }

Is this papering over an actual defect somewhere else?

Sort of.
It doesn't correct the underlying issue, but I think this should go in even along with the real fix.
The dmesg spamming has become a more serious problem for me than the underlying issue.
Someone had a patch rejected that completely suppressed the message.

Quoted 1 line

From my limited understanding, the hid spec allows an unlimited size

for an hid report , but the kernel only allocated 32 bits, which was more than anything used at that time. The 32 bit version is doing some bit shifting and possibly endian correction with the 32 bit field, so I was not comfortable just extending it to 192 or 256 bits without a little more understanding.

Quoted 1 line

Trivially, this could use "%s: ...", __func__, ...

True. I can make that change.

Quoted 1 line
#4 lore raw

PATCH v2 1/3 HID: core: reformat and reduce hid_printk macros

In reply to [email protected]

From: Joshua Clayton <[email protected]>

Reformat hid_printk macros to use standard __VA_ARGS__ syntax Remove hid_printk(), hid_emerg(), hid_crit(), and hid_alert(). Per Joe Perches these unused and likely never to be used.

---
 include/linux/hid.h | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
include/linux/hid.h +12 -20
index d770ab1a0479..b5e73331100e 100644
@@ -1154,29 +1154,21 @@ int hid_pidff_init(struct hid_device *hid);
 #define hid_pidff_init NULL
 #endif
 
-#define dbg_hid(format, arg...)						\
+#define dbg_hid(fmt, ...)						\
 do {									\
 	if (hid_debug)							\
-		printk(KERN_DEBUG "%s: " format, __FILE__, ##arg);	\
+		printk(KERN_DEBUG "%s: " fmt, __FILE__, ##__VA_ARGS__)	\
 } while (0)
 
-#define hid_printk(level, hid, fmt, arg...)		\
-	dev_printk(level, &(hid)->dev, fmt, ##arg)
-#define hid_emerg(hid, fmt, arg...)			\
-	dev_emerg(&(hid)->dev, fmt, ##arg)
-#define hid_crit(hid, fmt, arg...)			\
-	dev_crit(&(hid)->dev, fmt, ##arg)
-#define hid_alert(hid, fmt, arg...)			\
-	dev_alert(&(hid)->dev, fmt, ##arg)
-#define hid_err(hid, fmt, arg...)			\
-	dev_err(&(hid)->dev, fmt, ##arg)
-#define hid_notice(hid, fmt, arg...)			\
-	dev_notice(&(hid)->dev, fmt, ##arg)
-#define hid_warn(hid, fmt, arg...)			\
-	dev_warn(&(hid)->dev, fmt, ##arg)
-#define hid_info(hid, fmt, arg...)			\
-	dev_info(&(hid)->dev, fmt, ##arg)
-#define hid_dbg(hid, fmt, arg...)			\
-	dev_dbg(&(hid)->dev, fmt, ##arg)
+#define hid_err(hid, fmt, ...)				\
+	dev_err(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice(hid, fmt, ...)			\
+	dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn(hid, fmt, ...)				\
+	dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info(hid, fmt, ...)				\
+	dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg(hid, fmt, ...)				\
+	dev_dbg(&(hid)->dev, fmt, ##__VA_ARGS__)
 
 #endif
Signature · 1 line
2.21.0
#5 lore raw

PATCH v2 2/3 HID: core: Add printk_once variants to hid_warn() etc

From: Joshua Clayton <[email protected]>

hid_warn_once() is needed, add the others as part of the block

---
 include/linux/hid.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/hid.h +11 -0
index b5e73331100e..306dde3760a4 100644
@@ -1171,4 +1171,15 @@ do {									\
 #define hid_dbg(hid, fmt, ...)				\
 	dev_dbg(&(hid)->dev, fmt, ##__VA_ARGS__)
 
+#define hid_err_once(hid, fmt, ...)			\
+	dev_err_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice_once(hid, fmt, ...)			\
+	dev_notice_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn_once(hid, fmt, ...)			\
+	dev_warn_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info_once(hid, fmt, ...)			\
+	dev_info_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg_once(hid, fmt, ...)			\
+	dev_dbg_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+
 #endif
Signature · 1 line
2.21.0
#6 lore raw

PATCH v2 3/3 HID: core: only warn once of oversize hid report

In reply to [email protected]

From: Joshua Clayton <[email protected]>

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all else
Protect dmesg by printing the warning only one time.

---
 drivers/hid/hid-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +2 -2
index 210b81a56e1a..0cb53dddf341 100644
@@ -1311,8 +1311,8 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
 			unsigned offset, unsigned n)
 {
 	if (n > 32) {
-		hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
-			 n, current->comm);
+		hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n",
+			      __func__ ,n , current->comm);
 		n = 32;
 	}
 
Signature · 1 line
2.21.0
#7 lore raw

Re: [PATCH v2 3/3] HID: core: only warn once of oversize hid report

Quoted 1 line · On Mon, 2019-07-22 at 15:26 -0600, [email protected] wrote:

From: Joshua Clayton <[email protected]>

Thanks Joshua

Quoted 4 lines

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all else
Protect dmesg by printing the warning only one time.

[]

drivers/hid/hid-core.c

Quoted 1 line
drivers/hid/hid-core.c +0 -0

[]

drivers/hid/hid-core.c u32 hid_field_extract(const struct hid_device *hid, u8 *report, · line 1315

Quoted 8 lines
drivers/hid/hid-core.c +2 -2
@@ -1311,8 +1311,8 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
 			unsigned offset, unsigned n)
 {
 	if (n > 32) {
-		hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
-			 n, current->comm);
+		hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n",
+			      __func__ ,n , current->comm);

All the other bits are fine, but this line is oddly written with unusual spacing around 'n'.

Normally it'd be something like:

		hid_warn_once(hid, "%s: called with n (%d) > 32! (%s)\n",
			      __func__, n, current->comm);
#8 lore raw

Re: [PATCH v2 3/3] HID: core: only warn once of oversize hid report

Quoted 25 lines · Joe Perches
Quoted 1 line · On Mon, 2019-07-22 at 15:26 -0600, [email protected] wrote:

From: Joshua Clayton <[email protected]>

Thanks Joshua

Quoted 4 lines

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all else
Protect dmesg by printing the warning only one time.

[]

drivers/hid/hid-core.c

Quoted 1 line
drivers/hid/hid-core.c +0 -0

[]

drivers/hid/hid-core.c u32 hid_field_extract(const struct hid_device *hid, u8 *report, · line 1315

Quoted 8 lines
drivers/hid/hid-core.c +2 -2
@@ -1311,8 +1311,8 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
                      unsigned offset, unsigned n)
 {
      if (n > 32) {
-             hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
-                      n, current->comm);
+             hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n",
+                           __func__ ,n , current->comm);

All the other bits are fine, but this line is oddly written with unusual spacing around 'n'.

Quoted 4 lines

Normally it'd be something like:

                hid_warn_once(hid, "%s: called with n (%d) > 32! (%s)\n",
                              __func__, n, current->comm);

Gah!
Not only that but I missed a semicolon in patch 1. Will fix, (compile) and send v3 pdq.
Sorry about the extra noise.

Quoted 2 lines
#9 lore raw

PATCH v3 1/3 HID: core: reformat and reduce hid_printk macros

In reply to [email protected]

From: Joshua Clayton <[email protected]>

Reformat hid_printk macros to use standard __VA_ARGS__ syntax Remove hid_printk(), hid_emerg(), hid_crit(), and hid_alert(). Per Joe Perches these unused and likely never to be used.

---
 include/linux/hid.h | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
include/linux/hid.h +12 -20
index d770ab1a0479..e6c7efdb0458 100644
@@ -1154,29 +1154,21 @@ int hid_pidff_init(struct hid_device *hid);
 #define hid_pidff_init NULL
 #endif
 
-#define dbg_hid(format, arg...)						\
+#define dbg_hid(fmt, ...)						\
 do {									\
 	if (hid_debug)							\
-		printk(KERN_DEBUG "%s: " format, __FILE__, ##arg);	\
+		printk(KERN_DEBUG "%s: " fmt, __FILE__, ##__VA_ARGS__);	\
 } while (0)
 
-#define hid_printk(level, hid, fmt, arg...)		\
-	dev_printk(level, &(hid)->dev, fmt, ##arg)
-#define hid_emerg(hid, fmt, arg...)			\
-	dev_emerg(&(hid)->dev, fmt, ##arg)
-#define hid_crit(hid, fmt, arg...)			\
-	dev_crit(&(hid)->dev, fmt, ##arg)
-#define hid_alert(hid, fmt, arg...)			\
-	dev_alert(&(hid)->dev, fmt, ##arg)
-#define hid_err(hid, fmt, arg...)			\
-	dev_err(&(hid)->dev, fmt, ##arg)
-#define hid_notice(hid, fmt, arg...)			\
-	dev_notice(&(hid)->dev, fmt, ##arg)
-#define hid_warn(hid, fmt, arg...)			\
-	dev_warn(&(hid)->dev, fmt, ##arg)
-#define hid_info(hid, fmt, arg...)			\
-	dev_info(&(hid)->dev, fmt, ##arg)
-#define hid_dbg(hid, fmt, arg...)			\
-	dev_dbg(&(hid)->dev, fmt, ##arg)
+#define hid_err(hid, fmt, ...)				\
+	dev_err(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice(hid, fmt, ...)			\
+	dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn(hid, fmt, ...)				\
+	dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info(hid, fmt, ...)				\
+	dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg(hid, fmt, ...)				\
+	dev_dbg(&(hid)->dev, fmt, ##__VA_ARGS__)
 
 #endif
Signature · 1 line
2.21.0
#10 lore raw

PATCH v3 2/3 HID: core: Add printk_once variants to hid_warn() etc

From: Joshua Clayton <[email protected]>

hid_warn_once() is needed, add the others as part of the block

---
 include/linux/hid.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/hid.h +11 -0
index e6c7efdb0458..cd41f209043f 100644
@@ -1171,4 +1171,15 @@ do {									\
 #define hid_dbg(hid, fmt, ...)				\
 	dev_dbg(&(hid)->dev, fmt, ##__VA_ARGS__)
 
+#define hid_err_once(hid, fmt, ...)			\
+	dev_err_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_notice_once(hid, fmt, ...)			\
+	dev_notice_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn_once(hid, fmt, ...)			\
+	dev_warn_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_info_once(hid, fmt, ...)			\
+	dev_info_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_dbg_once(hid, fmt, ...)			\
+	dev_dbg_once(&(hid)->dev, fmt, ##__VA_ARGS__)
+
 #endif
Signature · 1 line
2.21.0
#11 lore raw

PATCH v3 3/3 HID: core: only warn once of oversize hid report

In reply to [email protected]

From: Joshua Clayton <[email protected]>

On HP spectre x360 convertible the message:
hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2) is continually printed many times per second, crowding out all else
Protect dmesg by printing the warning only one time.

---
 drivers/hid/hid-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +2 -2
index 210b81a56e1a..3eaee2c37931 100644
@@ -1311,8 +1311,8 @@ u32 hid_field_extract(const struct hid_device *hid, u8 *report,
 			unsigned offset, unsigned n)
 {
 	if (n > 32) {
-		hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
-			 n, current->comm);
+		hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n",
+			      __func__, n, current->comm);
 		n = 32;
 	}
 
Signature · 1 line
2.21.0