* [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS
@ 2021-04-19 10:42 Rasmus Villemoes
2021-04-19 11:03 ` Greg Kroah-Hartman
2021-05-13 18:41 ` Greg Kroah-Hartman
0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2021-04-19 10:42 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki
Cc: Andrzej Hajda, Rasmus Villemoes, linux-kernel
When debugfs is not enabled, the deferred_probe_reason string is never
read. So there's no reason to spend time and memory on recording it.
There's still a bunch of redundant kfree(NULL) calls and NULL
assignments, but this gives most of the benefit (avoiding two
vsnprintf() and a kmalloc()) for the minimal amount of ifdeffery.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/base/dd.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 37a5e5f8b221..6a197336c6a4 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -216,9 +216,13 @@ void device_unblock_probing(void)
* device_set_deferred_probe_reason() - Set defer probe reason message for device
* @dev: the pointer to the struct device
* @vaf: the pointer to va_format structure with message
+ *
+ * The ->deferred_probe_reason string is only ever read when debugfs
+ * is enabled, so this is a no-op for !CONFIG_DEBUG_FS.
*/
void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
{
+#ifdef CONFIG_DEBUG_FS
const char *drv = dev_driver_string(dev);
mutex_lock(&deferred_probe_mutex);
@@ -227,6 +231,7 @@ void device_set_deferred_probe_reason(const struct device *dev, struct va_format
dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
mutex_unlock(&deferred_probe_mutex);
+#endif
}
/*
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS
2021-04-19 10:42 [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS Rasmus Villemoes
@ 2021-04-19 11:03 ` Greg Kroah-Hartman
2021-05-13 18:41 ` Greg Kroah-Hartman
1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-04-19 11:03 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Rafael J. Wysocki, Andrzej Hajda, linux-kernel
On Mon, Apr 19, 2021 at 12:42:56PM +0200, Rasmus Villemoes wrote:
> When debugfs is not enabled, the deferred_probe_reason string is never
> read. So there's no reason to spend time and memory on recording it.
How much time and memory is it?
> There's still a bunch of redundant kfree(NULL) calls and NULL
> assignments, but this gives most of the benefit (avoiding two
> vsnprintf() and a kmalloc()) for the minimal amount of ifdeffery.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> drivers/base/dd.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 37a5e5f8b221..6a197336c6a4 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -216,9 +216,13 @@ void device_unblock_probing(void)
> * device_set_deferred_probe_reason() - Set defer probe reason message for device
> * @dev: the pointer to the struct device
> * @vaf: the pointer to va_format structure with message
> + *
> + * The ->deferred_probe_reason string is only ever read when debugfs
> + * is enabled, so this is a no-op for !CONFIG_DEBUG_FS.
> */
> void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
> {
> +#ifdef CONFIG_DEBUG_FS
> const char *drv = dev_driver_string(dev);
>
> mutex_lock(&deferred_probe_mutex);
> @@ -227,6 +231,7 @@ void device_set_deferred_probe_reason(const struct device *dev, struct va_format
> dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
>
> mutex_unlock(&deferred_probe_mutex);
> +#endif
I really don't like #ifdef in .c files. Any way to put this in the .h
file instead like should be done properly?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS
2021-04-19 10:42 [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS Rasmus Villemoes
2021-04-19 11:03 ` Greg Kroah-Hartman
@ 2021-05-13 18:41 ` Greg Kroah-Hartman
1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-05-13 18:41 UTC (permalink / raw)
To: Rasmus Villemoes; +Cc: Rafael J. Wysocki, Andrzej Hajda, linux-kernel
On Mon, Apr 19, 2021 at 12:42:56PM +0200, Rasmus Villemoes wrote:
> When debugfs is not enabled, the deferred_probe_reason string is never
> read. So there's no reason to spend time and memory on recording it.
>
> There's still a bunch of redundant kfree(NULL) calls and NULL
> assignments, but this gives most of the benefit (avoiding two
> vsnprintf() and a kmalloc()) for the minimal amount of ifdeffery.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> drivers/base/dd.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 37a5e5f8b221..6a197336c6a4 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -216,9 +216,13 @@ void device_unblock_probing(void)
> * device_set_deferred_probe_reason() - Set defer probe reason message for device
> * @dev: the pointer to the struct device
> * @vaf: the pointer to va_format structure with message
> + *
> + * The ->deferred_probe_reason string is only ever read when debugfs
> + * is enabled, so this is a no-op for !CONFIG_DEBUG_FS.
> */
> void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
> {
> +#ifdef CONFIG_DEBUG_FS
> const char *drv = dev_driver_string(dev);
>
> mutex_lock(&deferred_probe_mutex);
> @@ -227,6 +231,7 @@ void device_set_deferred_probe_reason(const struct device *dev, struct va_format
> dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
>
> mutex_unlock(&deferred_probe_mutex);
> +#endif
Can you move the #ifdef to a .h file and do this properly instead of
cutting up the function like this?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-13 18:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 10:42 [PATCH] driver core: make device_set_deferred_probe_reason a no-op when !CONFIG_DEBUG_FS Rasmus Villemoes
2021-04-19 11:03 ` Greg Kroah-Hartman
2021-05-13 18:41 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).