[PATCH 2/2] Declare debug_mask in debugfs

YanBo dreamfly281 at gmail.com
Wed Jul 10 10:24:07 EDT 2013


On Tue, Jul 9, 2013 at 10:59 PM, Eugene Krasnikov <k.eugene.e at gmail.com> wrote:
> Now debug_mask can be changed in runtime.
>
> Signed-off-by: Eugene Krasnikov <k.eugene.e at gmail.com>
> ---
>  debug.c | 37 +++++++++++++++++++++++++++++++++++++
>  debug.h |  1 +
>  2 files changed, 38 insertions(+)
>
> diff --git a/debug.c b/debug.c
> index 4dcaa82..529dd54 100644
> --- a/debug.c
> +++ b/debug.c
> @@ -123,6 +123,41 @@ static const struct file_operations fops_wcn36xx_dump = {
>         .write =       write_file_dump,
>  };
>
> +static ssize_t read_file_debug_mask(struct file *file, char __user *user_buf,
> +                                  size_t count, loff_t *ppos)
> +{
> +       char buf[32];
> +       unsigned int len;
> +       len = snprintf(buf, 32, "0x%08x\n", debug_mask);
> +       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
> +}
> +
> +static ssize_t write_file_debug_mask(struct file *file,
> +                                   const char __user *user_buf,
> +                                   size_t count, loff_t *ppos)
> +{
> +       unsigned long mask;
> +       char buf[32];
> +       ssize_t len;
> +
> +       len = min(count, sizeof(buf) - 1);
> +       if (copy_from_user(buf, user_buf, len))
> +               return -EFAULT;
> +
> +       buf[len] = '\0';
> +       if (kstrtoul(buf, 0, &mask))
> +               return -EINVAL;
> +
> +       debug_mask = mask;
> +       return count;
> +}
> +
> +static const struct file_operations fops_wcn36xx_debug_mask = {
> +       .open  =       wcn36xx_debugfs_open,
> +       .read  =       read_file_debug_mask,
> +       .write =       write_file_debug_mask,
> +};
> +
>  #define ADD_FILE(name, mode, fop, priv_data)           \
>         do {                                                    \
>                 struct dentry *d;                               \
> @@ -150,6 +185,8 @@ void wcn36xx_debugfs_init(struct wcn36xx *wcn)
>         ADD_FILE(bmps_switcher, S_IRUSR | S_IWUSR,
>                       &fops_wcn36xx_bmps, wcn);
>         ADD_FILE(dump, S_IWUSR, &fops_wcn36xx_dump, wcn);
> +       ADD_FILE(debug_mask, S_IRUSR | S_IWUSR,
> +                     &fops_wcn36xx_debug_mask, wcn);
>  }
>
>  void wcn36xx_debugfs_exit(struct wcn36xx *wcn)
> diff --git a/debug.h b/debug.h
> index 5bafc7e..3a3cf5f 100644
> --- a/debug.h
> +++ b/debug.h
> @@ -35,6 +35,7 @@ struct wcn36xx_dfs_entry {
>         struct dentry *rootdir;
>         struct wcn36xx_dfs_file file_bmps_switcher;
>         struct wcn36xx_dfs_file file_dump;
> +       struct wcn36xx_dfs_file file_debug_mask;
>  };
>
>  void wcn36xx_debugfs_init(struct wcn36xx *wcn);
> --
> 1.7.11.3

Very useful feature for debug.
Just one topic, if we use debugfs dynamic control the debug log, do we
still need the debug_mask as module parameter?
if no, how about move the debug_mask from a global variable  to a
element of the wcn  structure?



More information about the wcn36xx mailing list