Add debugfs interface to read System Manager syslog info
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/firmware/imx/sm-misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/drivers/firmware/imx/sm-misc.c b/drivers/firmware/imx/sm-misc.c
index fc3ee12c2be878e0285183e3381c9514a63d5142..4678d76b7dd6907533b5131c15ff0edcb66f43b2 100644
--- a/drivers/firmware/imx/sm-misc.c
+++ b/drivers/firmware/imx/sm-misc.c
@@ -3,12 +3,15 @@
* Copyright 2024 NXP
*/
+#include <linux/debugfs.h>
+#include <linux/device/devres.h>
#include <linux/firmware/imx/sm.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/scmi_protocol.h>
#include <linux/scmi_imx_protocol.h>
+#include <linux/seq_file.h>
static const struct scmi_imx_misc_proto_ops *imx_misc_ctrl_ops;
static struct scmi_protocol_handle *ph;
@@ -44,10 +47,43 @@ static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb,
return 0;
}
+static int syslog_show(struct seq_file *file, void *priv)
+{
+ struct device *dev = file->private;
+ /* 4KB is large enough for syslog */
+ void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL);
+ /* syslog API use num words, not num bytes */
+ u16 size = SZ_4K / 4;
+ int ret;
+
+ if (!ph)
+ return -ENODEV;
+
+ ret = imx_misc_ctrl_ops->misc_syslog(ph, &size, syslog);
+ if (ret) {
+ if (size > SZ_4K / 4) {
+ dev_err(dev, "syslog size is larger than 4KB, please enlarge\n");
+ return ret;
+ }
+ }
+
+ seq_hex_dump(file, " ", DUMP_PREFIX_NONE, 16, sizeof(u32), syslog, size * 4, false);
+ seq_putc(file, '\n');
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(syslog);
+
+static void scmi_imx_misc_put(void *p)
+{
+ debugfs_remove((struct dentry *)p);
+}
+
static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
{
const struct scmi_handle *handle = sdev->handle;
struct device_node *np = sdev->dev.of_node;
+ struct dentry *scmi_imx_dentry;
u32 src_id, flags;
int ret, i, num;
@@ -98,6 +134,12 @@ static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
}
}
+ scmi_imx_dentry = debugfs_create_dir("scmi_imx", NULL);
+ if (!IS_ERR(scmi_imx_dentry))
+ debugfs_create_file("syslog", 0444, scmi_imx_dentry, &sdev->dev, &syslog_fops);
+
+ devm_add_action_or_reset(&sdev->dev, scmi_imx_misc_put, scmi_imx_dentry);
+
return 0;
}
--
2.37.1
Hi Peng,
kernel test robot noticed the following build errors:
[auto build test ERROR on 65dd046ef55861190ecde44c6d9fcde54b9fb77d]
url: https://github.com/intel-lab-lkp/linux/commits/Peng-Fan/firmware-arm_scmi-imx-Support-getting-syslog-of-MISC-protocol/20250910-223316
base: 65dd046ef55861190ecde44c6d9fcde54b9fb77d
patch link: https://lore.kernel.org/r/20250910-sm-syslog-v1-2-5b36f8f21da6%40nxp.com
patch subject: [PATCH 2/2] firmware: imx: sm-misc: Dump syslog info
config: i386-buildonly-randconfig-004-20250912 (https://download.01.org/0day-ci/archive/20250912/202509120758.omltrDMi-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250912/202509120758.omltrDMi-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202509120758.omltrDMi-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/firmware/imx/sm-misc.c:54:39: error: use of undeclared identifier 'SZ_4K'
54 | void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL);
| ^
>> drivers/firmware/imx/sm-misc.c:54:39: error: use of undeclared identifier 'SZ_4K'
>> drivers/firmware/imx/sm-misc.c:54:39: error: use of undeclared identifier 'SZ_4K'
drivers/firmware/imx/sm-misc.c:56:13: error: use of undeclared identifier 'SZ_4K'
56 | u16 size = SZ_4K / 4;
| ^
drivers/firmware/imx/sm-misc.c:64:14: error: use of undeclared identifier 'SZ_4K'
64 | if (size > SZ_4K / 4) {
| ^
drivers/firmware/imx/sm-misc.c:64:14: error: use of undeclared identifier 'SZ_4K'
drivers/firmware/imx/sm-misc.c:64:14: error: use of undeclared identifier 'SZ_4K'
7 errors generated.
vim +/SZ_4K +54 drivers/firmware/imx/sm-misc.c
49
50 static int syslog_show(struct seq_file *file, void *priv)
51 {
52 struct device *dev = file->private;
53 /* 4KB is large enough for syslog */
> 54 void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL);
55 /* syslog API use num words, not num bytes */
56 u16 size = SZ_4K / 4;
57 int ret;
58
59 if (!ph)
60 return -ENODEV;
61
62 ret = imx_misc_ctrl_ops->misc_syslog(ph, &size, syslog);
63 if (ret) {
64 if (size > SZ_4K / 4) {
65 dev_err(dev, "syslog size is larger than 4KB, please enlarge\n");
66 return ret;
67 }
68 }
69
70 seq_hex_dump(file, " ", DUMP_PREFIX_NONE, 16, sizeof(u32), syslog, size * 4, false);
71 seq_putc(file, '\n');
72
73 return 0;
74 }
75 DEFINE_SHOW_ATTRIBUTE(syslog);
76
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On Wed, Sep 10, 2025 at 10:28:18PM +0800, Peng Fan wrote:
> static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
> {
> const struct scmi_handle *handle = sdev->handle;
> struct device_node *np = sdev->dev.of_node;
> + struct dentry *scmi_imx_dentry;
> u32 src_id, flags;
> int ret, i, num;
>
> @@ -98,6 +134,12 @@ static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
> }
> }
>
> + scmi_imx_dentry = debugfs_create_dir("scmi_imx", NULL);
> + if (!IS_ERR(scmi_imx_dentry))
> + debugfs_create_file("syslog", 0444, scmi_imx_dentry, &sdev->dev, &syslog_fops);
You don't need the IS_ERR() check. If debugfs_create_dir() fails then
just pass the error pointer to debugfs_create_file(), it's fine.
regards,
dan carpenter
> +
> + devm_add_action_or_reset(&sdev->dev, scmi_imx_misc_put, scmi_imx_dentry);
> +
> return 0;
> }
>
>
> --
> 2.37.1
>
On Wed, Sep 10, 2025 at 10:28:18PM +0800, Peng Fan wrote:
> Add debugfs interface to read System Manager syslog info
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
> drivers/firmware/imx/sm-misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/drivers/firmware/imx/sm-misc.c b/drivers/firmware/imx/sm-misc.c
> index fc3ee12c2be878e0285183e3381c9514a63d5142..4678d76b7dd6907533b5131c15ff0edcb66f43b2 100644
> --- a/drivers/firmware/imx/sm-misc.c
> +++ b/drivers/firmware/imx/sm-misc.c
> @@ -3,12 +3,15 @@
> * Copyright 2024 NXP
> */
>
> +#include <linux/debugfs.h>
> +#include <linux/device/devres.h>
> #include <linux/firmware/imx/sm.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/scmi_protocol.h>
> #include <linux/scmi_imx_protocol.h>
> +#include <linux/seq_file.h>
>
> static const struct scmi_imx_misc_proto_ops *imx_misc_ctrl_ops;
> static struct scmi_protocol_handle *ph;
> @@ -44,10 +47,43 @@ static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb,
> return 0;
> }
>
> +static int syslog_show(struct seq_file *file, void *priv)
> +{
> + struct device *dev = file->private;
> + /* 4KB is large enough for syslog */
> + void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL);
> + /* syslog API use num words, not num bytes */
> + u16 size = SZ_4K / 4;
> + int ret;
> +
> + if (!ph)
> + return -ENODEV;
> +
> + ret = imx_misc_ctrl_ops->misc_syslog(ph, &size, syslog);
> + if (ret) {
> + if (size > SZ_4K / 4) {
> + dev_err(dev, "syslog size is larger than 4KB, please enlarge\n");
> + return ret;
suppose it is never happen, you pass down size to misc_syslog, it should
never write data more than size.
I am not sure what means of misc_syslog() return value. Generally it should
be how many data in pointer 'syslog' if return value > 0.
So seq_hex_dump() should use ret value. Then only dump validate data,
instead of the whole buffer.
Frank
> + }
> + }
> +
> + seq_hex_dump(file, " ", DUMP_PREFIX_NONE, 16, sizeof(u32), syslog, size * 4, false);
> + seq_putc(file, '\n');
> +
> + return 0;
> +}
> +DEFINE_SHOW_ATTRIBUTE(syslog);
> +
> +static void scmi_imx_misc_put(void *p)
> +{
> + debugfs_remove((struct dentry *)p);
> +}
> +
> static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
> {
> const struct scmi_handle *handle = sdev->handle;
> struct device_node *np = sdev->dev.of_node;
> + struct dentry *scmi_imx_dentry;
> u32 src_id, flags;
> int ret, i, num;
>
> @@ -98,6 +134,12 @@ static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
> }
> }
>
> + scmi_imx_dentry = debugfs_create_dir("scmi_imx", NULL);
> + if (!IS_ERR(scmi_imx_dentry))
> + debugfs_create_file("syslog", 0444, scmi_imx_dentry, &sdev->dev, &syslog_fops);
> +
> + devm_add_action_or_reset(&sdev->dev, scmi_imx_misc_put, scmi_imx_dentry);
> +
> return 0;
> }
>
>
> --
> 2.37.1
>
Hi Frank,
On Wed, Sep 10, 2025 at 11:25:04AM -0400, Frank Li wrote:
>On Wed, Sep 10, 2025 at 10:28:18PM +0800, Peng Fan wrote:
[...]
>> +static int syslog_show(struct seq_file *file, void *priv)
>> +{
>> + struct device *dev = file->private;
>> + /* 4KB is large enough for syslog */
>> + void *syslog __free(kfree) = kmalloc(SZ_4K, GFP_KERNEL);
>> + /* syslog API use num words, not num bytes */
>> + u16 size = SZ_4K / 4;
>> + int ret;
>> +
>> + if (!ph)
>> + return -ENODEV;
>> +
>> + ret = imx_misc_ctrl_ops->misc_syslog(ph, &size, syslog);
>> + if (ret) {
>> + if (size > SZ_4K / 4) {
>> + dev_err(dev, "syslog size is larger than 4KB, please enlarge\n");
>> + return ret;
>
size could be runtime updated with the returned syslog size.
>suppose it is never happen, you pass down size to misc_syslog, it should
>never write data more than size.
Right. But size could be updated even it not write data more than the input
size.
>
>I am not sure what means of misc_syslog() return value. Generally it should
>be how many data in pointer 'syslog' if return value > 0.
>
>So seq_hex_dump() should use ret value. Then only dump validate data,
>instead of the whole buffer.
size has been updated by misc_syslog, so it is not to dump whole buffer.
Thanks,
Peng
>
>Frank
>
>> + }
>> + }
>> +
>> + seq_hex_dump(file, " ", DUMP_PREFIX_NONE, 16, sizeof(u32), syslog, size * 4, false);
>> + seq_putc(file, '\n');
>> +
>> + return 0;
>> +}
>> +DEFINE_SHOW_ATTRIBUTE(syslog);
>> +
>> +static void scmi_imx_misc_put(void *p)
>> +{
>> + debugfs_remove((struct dentry *)p);
>> +}
>> +
>> static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
>> {
>> const struct scmi_handle *handle = sdev->handle;
>> struct device_node *np = sdev->dev.of_node;
>> + struct dentry *scmi_imx_dentry;
>> u32 src_id, flags;
>> int ret, i, num;
>>
>> @@ -98,6 +134,12 @@ static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
>> }
>> }
>>
>> + scmi_imx_dentry = debugfs_create_dir("scmi_imx", NULL);
>> + if (!IS_ERR(scmi_imx_dentry))
>> + debugfs_create_file("syslog", 0444, scmi_imx_dentry, &sdev->dev, &syslog_fops);
>> +
>> + devm_add_action_or_reset(&sdev->dev, scmi_imx_misc_put, scmi_imx_dentry);
>> +
>> return 0;
>> }
>>
>>
>> --
>> 2.37.1
>>
© 2016 - 2026 Red Hat, Inc.