Here is a (counter?) use-case for debug-print-classes.  It adds
read,write print-classes, and marks all pr_debugs in *_show and
*_store functions accordingly.

this allows manipulation of those categories as:

   echo "module kset-example mflags 1 +p" > /proc/dynamic_debug/control
   echo "module kset-example mflags 2 +p" > /proc/dynamic_debug/control

But this marking completely duplicates the callsite sets definable by:

   #> cat enable-show-store
   module kset-example function *_show +p
   module kset-example function *_store +p
   #> cat enable-show-store > /proc/dynamic_debug/control

IOW, dont over-use debug-print-class.  Your arbitrary subset of
pr-debug calls can be recreated by an N line script.
---
 samples/kobject/kset-example.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
index 27c9b1beec28..61d016cb6b4d 100644
--- a/samples/kobject/kset-example.c
+++ b/samples/kobject/kset-example.c
@@ -42,6 +42,27 @@ struct foo_attribute {
 };
 #define to_foo_attr(x) container_of(x, struct foo_attribute, attr)
 
+/*
+ * This module also uses pr_debug() to provide debug logging that
+ * makes it easy to see the module operating.  Just invoke as:
+ *     #> dmesg -w &
+ *     #> modprobe kset-example dyndbg=+pfml
+ *
+ * Further, we *arbitrarily* use pr_debug_n() to create 2 separate
+ * (non-default) print-classes, in the *_show and *_store functions.
+ *
+ * This allows selection by those categories:
+ *     echo "module kset-example mflags 1 +p" > dynamic_debug/control
+ *     echo "module kset-example mflags 2 +p" > dynamic_debug/control
+ * but that is clearer as:
+ *     echo "module kset-example function *_show +p" > dynamic_debug/control
+ *     echo "module kset-example function *_store +p" > dynamic_debug/control
+ *
+ * IOW - mostly you dont need non-default print-classes
+ */
+#define prCATr 1       /* print-class for show (r=read) */
+#define prCATw 2       /* print-class for store (w=write) */
+
 /*
  * The default show function that must be passed to sysfs.  This will be
  * called by sysfs for whenever a show function is called by the user on a
@@ -56,7 +77,7 @@ static ssize_t foo_attr_show(struct kobject *kobj,
        struct foo_attribute *attribute;
        struct foo_obj *foo;
 
-       pr_debug("called");
+       pr_debug_n(prCATr, "called");
        attribute = to_foo_attr(attr);
        foo = to_foo_obj(kobj);
 
@@ -77,7 +98,7 @@ static ssize_t foo_attr_store(struct kobject *kobj,
        struct foo_attribute *attribute;
        struct foo_obj *foo;
 
-       pr_debug("called");
+       pr_debug_n(prCATw, "called");
        attribute = to_foo_attr(attr);
        foo = to_foo_obj(kobj);
 
@@ -115,7 +136,7 @@ static void foo_release(struct kobject *kobj)
 static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
                        char *buf)
 {
-       pr_debug("called");
+       pr_debug_n(prCATr, "called");
        return sprintf(buf, "%d\n", foo_obj->foo);
 }
 
@@ -124,7 +145,7 @@ static ssize_t foo_store(struct foo_obj *foo_obj, struct 
foo_attribute *attr,
 {
        int ret;
 
-       pr_debug("called");
+       pr_debug_n(prCATw, "called");
        ret = kstrtoint(buf, 10, &foo_obj->foo);
        if (ret < 0)
                return ret;
@@ -145,7 +166,7 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct 
foo_attribute *attr,
 {
        int var;
 
-       pr_debug("called");
+       pr_debug_n(prCATr, "called");
        if (strcmp(attr->attr.name, "baz") == 0)
                var = foo_obj->baz;
        else
@@ -158,7 +179,7 @@ static ssize_t b_store(struct foo_obj *foo_obj, struct 
foo_attribute *attr,
 {
        int var, ret;
 
-       pr_debug("called");
+       pr_debug_n(prCATw, "called");
        ret = kstrtoint(buf, 10, &var);
        if (ret < 0)
                return ret;
-- 
2.26.2

Reply via email to