Fix vargs handling in iucv_alloc_device()
Subsystems (5)
Vasily Gorbik
maintainercover Fix vargs handling in iucv_alloc_device()
Export kobject_set_name_vargs() and use it in iucv_alloc_device() to fix vargs handling.
@Greg and Rafael:
Could you please ack the first patch so I can take both patches via the s390 tree?
Thank you
Heiko Carstens (1):
s390/iucv: Fix vargs handling in iucv_alloc_device()
Vasily Gorbik (1):
kobject: Export kobject_set_name_vargs() symbol
lib/kobject.c | 1 + net/iucv/iucv.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.41.0
Vasily Gorbik
maintainerPATCH 1/2 kobject: Export kobject_set_name_vargs() symbol
The net/iucv module requires the kobject_set_name_vargs() function to set kobject names dynamically based on variable arguments. Export the kobject_set_name_vargs() symbol, allowing the net/iucv module and other potential modules to use this utility function.
--- lib/kobject.c | 1 + 1 file changed, 1 insertion(+)
lib/kobject.c +1 -0
@@ -295,6 +295,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,return 0 ; } +EXPORT_SYMBOL (kobject_set_name_vargs);/** * kobject_set_name() - Set the name of a kobject.
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] kobject: Export kobject_set_name_vargs() symbol
Quoted 17 lines · Vasily Gorbik
The net/iucv module requires the
kobject_set_name_vargs()function to set kobject names dynamically based on variable arguments. Export thekobject_set_name_vargs()symbol, allowing the net/iucv module and other potential modules to use this utility function.Reported-by kernel test robot <[email protected]>Signed-off-by Vasily Gorbik <[email protected]>--- lib/kobject.c | 1 + 1 file changed, 1 insertion(+)lib/kobject.c +0
-0
lib/kobject.c int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, · line 298
Quoted 4 lines
lib/kobject.c +1
-0@@ -295,6 +295,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,return 0 ; } +EXPORT_SYMBOL (kobject_set_name_vargs);
EXPORT_SYMBOL_GPL() please.
thanks,
greg k-h
Vasily Gorbik
maintainerPATCH 2/2 s390/iucv: Fix vargs handling in iucv_alloc_device()
In reply to Vasily GorbikFrom: Heiko Carstens <[email protected]>
iucv_alloc_device() gets a format string and a varying number of arguments. This is incorrectly forwarded by calling dev_set_name() with the format string and a va_list, while dev_set_name() expects also a varying number of arguments.
Fix this and call kobject_set_name_vargs() instead which expects a va_list parameter.
Reference-ID: https://bugzilla.linux.ibm.com/show_bug.cgi?id=208008
--- net/iucv/iucv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/iucv/iucv.c +1 -1
@@ -92,7 +92,7 @@ struct device *iucv_alloc_device(const struct attribute_group **attrs,if (!dev) goto out_error;va_start (vargs, fmt); - rc =dev_set_name (dev, fmt, vargs); + rc =kobject_set_name_vargs (&dev->kobj, fmt, vargs);va_end (vargs);if (rc) goto out_error;
Signature · 1 line
2.41.0
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 9 lines · Vasily Gorbik
From: Heiko Carstens <[email protected]>
iucv_alloc_device()gets a format string and a varying number of arguments. This is incorrectly forwarded by callingdev_set_name()with the format string and ava_list, whiledev_set_name()expects also a varying number of arguments.Fix this and call
kobject_set_name_vargs()instead which expects ava_listparameter.
I don't understand, why can't dev_set_name() be called here?
Calling "raw" kobject functions is almost never the correct thing to be doing, ESPECIALLY as you have a struct device here.
thanks,
greg k-h
Vasily Gorbik
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Vasily Gorbik
From: Heiko Carstens <[email protected]>
iucv_alloc_device()gets a format string and a varying number of arguments. This is incorrectly forwarded by callingdev_set_name()with the format string and ava_list, whiledev_set_name()expects also a varying number of arguments.
Quoted 7 lines
Quoted 2 lines
Fix this and call
kobject_set_name_vargs()instead which expects ava_listparameter.I don't understand, why can't
dev_set_name()be called here?Calling "raw" kobject functions is almost never the correct thing to be doing, ESPECIALLY as you have a struct device here.
struct device *iucv_alloc_device(const struct attribute_group **attrs,
void *priv, const char *fmt, ...);
va_start(vargs, fmt); initializes vargs to point to the first argument after fmt.
__printf(2, 0) int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs);
__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
dev_set_name is expecting to receive individual variable arguments directly (...), not a va_list.
The (...) in dev_set_name is meant to be expanded into individual arguments, but when you pass a va_list to it, this expansion doesn't happen. Instead, the va_list is just treated as a pointer or a single argument, leading to undefined or incorrect behavior.
So, would it be okay to reuse kobject_set_name_vargs() here, or would you propose introducing another helper just for this case? e.g.
int dev_set_name_vargs(struct device *dev, const char *fmt, va_list vargs) {
჻·······return kobject_set_name_vargs(&dev->kobj, fmt, vargs); }EXPORT_SYMBOL_GPL(dev_set_name_vargs)
The bz link should be:
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 34 lines · Vasily Gorbik
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Vasily Gorbik
From: Heiko Carstens <[email protected]>
iucv_alloc_device()gets a format string and a varying number of arguments. This is incorrectly forwarded by callingdev_set_name()with the format string and ava_list, whiledev_set_name()expects also a varying number of arguments.Quoted 7 lines
Quoted 2 lines
Fix this and call
kobject_set_name_vargs()instead which expects ava_listparameter.I don't understand, why can't
dev_set_name()be called here?Calling "raw" kobject functions is almost never the correct thing to be doing, ESPECIALLY as you have a struct device here.
struct device *iucv_alloc_device(const struct
attribute_group**attrs,void *priv, const char *fmt, ...);
va_start(vargs, fmt); initializes vargs to point to the first argument after fmt.
__printf(2, 0)intkobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs);
__printf(2, 3)intdev_set_name(struct device *dev, const char *name, ...);
dev_set_nameis expecting to receive individual variable arguments directly (...), not ava_list.The (...) in
dev_set_nameis meant to be expanded into individual arguments, but when you pass ava_listto it, this expansion doesn't happen. Instead, theva_listis just treated as a pointer or a single argument, leading to undefined or incorrect behavior.
Quoted 8 lines
So, would it be okay to reuse
kobject_set_name_vargs()here, or would you propose introducing another helper just for this case? e.g.int
dev_set_name_vargs(struct device *dev, const char *fmt, va_list vargs){
჻·······returnkobject_set_name_vargs(&dev->kobj, fmt, vargs); }EXPORT_SYMBOL_GPL(dev_set_name_vargs)
This function makes more sense if you really want to do this.
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
thanks,
greg k-h
Vasily Gorbik
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 44 lines · Greg Kroah-Hartman
Quoted 34 lines · Vasily Gorbik
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Vasily Gorbik
From: Heiko Carstens <[email protected]>
iucv_alloc_device()gets a format string and a varying number of arguments. This is incorrectly forwarded by callingdev_set_name()with the format string and ava_list, whiledev_set_name()expects also a varying number of arguments.Quoted 7 lines
Quoted 2 lines
Fix this and call
kobject_set_name_vargs()instead which expects ava_listparameter.I don't understand, why can't
dev_set_name()be called here?Calling "raw" kobject functions is almost never the correct thing to be doing, ESPECIALLY as you have a struct device here.
struct device *iucv_alloc_device(const struct
attribute_group**attrs,void *priv, const char *fmt, ...);
va_start(vargs, fmt); initializes vargs to point to the first argument after fmt.
__printf(2, 0)intkobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs);
__printf(2, 3)intdev_set_name(struct device *dev, const char *name, ...);
dev_set_nameis expecting to receive individual variable arguments directly (...), not ava_list.The (...) in
dev_set_nameis meant to be expanded into individual arguments, but when you pass ava_listto it, this expansion doesn't happen. Instead, theva_listis just treated as a pointer or a single argument, leading to undefined or incorrect behavior.Quoted 8 lines
So, would it be okay to reuse
kobject_set_name_vargs()here, or would you propose introducing another helper just for this case? e.g.int
dev_set_name_vargs(struct device *dev, const char *fmt, va_list vargs){
჻·······returnkobject_set_name_vargs(&dev->kobj, fmt, vargs); }EXPORT_SYMBOL_GPL(dev_set_name_vargs)
Quoted 5 lines
This function makes more sense if you really want to do this.
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
That's comming from this patch series:
https://lore.kernel.org/all/[email protected]/#t
"""
Unify IUCV device allocation as suggested by Arnd Bergmann in order to get rid of code duplication in various device drivers. """
It just introduces and utilizes a couple of wrappers to reduce code duplication, and in this case, introducing this level of indirection led to the need for forwarding vargs.
And reimplementing parts of kobject_set_name_vargs to format the device name beforehand is probably not what we want.
Alexandra Winter
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
In reply to Greg Kroah-HartmanQuoted 2 lines · Greg Kroah-Hartman
Quoted 2 lines
Quoted 2 lines
I don't understand, why can't
dev_set_name()be called here?
[...]
Quoted 6 lines
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
thanks,
Vasily, the following update to Heiko's patch does not touch lib/kobject.c According to a quick test it still solves the original issue and does compile with W=1 and iucv as a module.
net/iucv/iucv.c +4 -1
@@ -86,13 +86,17 @@ struct device *iucv_alloc_device(const struct attribute_group **attrs, {struct device *dev;va_list vargs; +char buf[20 ];int rc; dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) goto out_error;va_start (vargs, fmt); - rc =kobject_set_name_vargs (&dev->kobj, fmt, vargs); + rc =vsnprintf (buf,20 , fmt, vargs); +if (!rc) + rc =dev_set_name (dev, buf);va_end (vargs);if (rc) goto out_error;
Maybe Greg has somethign like this in mind?
Vasily Gorbik
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 41 lines · Alexandra Winter
Quoted 2 lines · Greg Kroah-Hartman
Quoted 2 lines
Quoted 2 lines
I don't understand, why can't
dev_set_name()be called here?[...]
Quoted 6 lines
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
thanks,
Vasily, the following update to Heiko's patch does not touch
lib/kobject.cAccording to a quick test it still solves the original issue and does compile with W=1 and iucv as a module.net/iucv/iucv.c +4
-1@@ -86,13 +86,17 @@ struct device *iucv_alloc_device(const struct attribute_group **attrs, {struct device *dev;va_list vargs; +char buf[20 ];int rc; dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) goto out_error;va_start (vargs, fmt); - rc =kobject_set_name_vargs (&dev->kobj, fmt, vargs); + rc =vsnprintf (buf,20 , fmt, vargs); +if (!rc) + rc =dev_set_name (dev, buf);va_end (vargs);if (rc) goto out_error;
Quoted 1 line
Maybe Greg has somethign like this in mind?
Thanks Alexandra,
but I'm still leaning towards forwarding vargs and avoid splitting the name formatting logic, if Greg agrees that the use case justifies adding a new helper. Let's see what Greg prefers.
int dev_set_name_vargs(struct device *dev, const char *fmt, va_list vargs)
{
return kobject_set_name_vargs(&dev->kobj, fmt, vargs);
}EXPORT_SYMBOL_GPL(dev_set_name_vargs)
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
In reply to Alexandra WinterQuoted 27 lines · Alexandra Winter
Quoted 2 lines · Greg Kroah-Hartman
Quoted 2 lines
Quoted 2 lines
I don't understand, why can't
dev_set_name()be called here?[...]
Quoted 6 lines
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
thanks,
Vasily, the following update to Heiko's patch does not touch
lib/kobject.cAccording to a quick test it still solves the original issue and does compile with W=1 and iucv as a module.net/iucv/iucv.c +1
-0@@ -86,13 +86,17 @@ struct device *iucv_alloc_device(const struct attribute_group **attrs, {struct device *dev;va_list vargs; +char buf[20 ];
net/iucv/iucv.c struct device *iucv_alloc_device(const struct attribute_group **attrs, · line 98
Quoted 10 lines
net/iucv/iucv.c +3
-1int rc; dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) goto out_error;va_start (vargs, fmt); - rc =kobject_set_name_vargs (&dev->kobj, fmt, vargs); + rc =vsnprintf (buf,20 , fmt, vargs); +if (!rc) + rc =dev_set_name (dev, buf);
This looks best, let's not create a core function that no one has ever needed yet just for one user :)
thanks,
greg k-h
Vasily Gorbik
maintainerRe: [PATCH 2/2] s390/iucv: Fix vargs handling in iucv_alloc_device()
Quoted 30 lines · Greg Kroah-Hartman
Quoted 29 lines · Alexandra Winter
Quoted 2 lines · Greg Kroah-Hartman
Quoted 2 lines
Quoted 2 lines
I don't understand, why can't
dev_set_name()be called here?[...]
Quoted 6 lines
But step back, why is this needed at all anyway? No other subsystem or driver needs/wants this, what makes this api so special? Why not figure out your name beforehand?
thanks,
Vasily, the following update to Heiko's patch does not touch
lib/kobject.cAccording to a quick test it still solves the original issue and does compile with W=1 and iucv as a module.net/iucv/iucv.c +1
-0@@ -86,13 +86,17 @@ struct device *iucv_alloc_device(const struct attribute_group **attrs, {struct device *dev;va_list vargs; +char buf[20 ];int rc;
Quoted 11 lines
net/iucv/iucv.c struct device *iucv_alloc_device(const struct attribute_group **attrs, · line 98
Quoted 8 lines
net/iucv/iucv.c +3
-1dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) goto out_error;va_start (vargs, fmt); - rc =kobject_set_name_vargs (&dev->kobj, fmt, vargs); + rc =vsnprintf (buf,20 , fmt, vargs); +if (!rc) + rc =dev_set_name (dev, buf);This looks best, let's not create a core function that no one has ever needed yet just for one user :)
Okay, fair enough. Thank you, Greg!
I'll drop these two patches. Alexandra, I assume you will send out your alternative fix separately. Thank you!