Per-device parameter support (2/16)
dp_02_param_array_bug.diff
This is the 2nd patch of 16 patches for devparam.
This patches fixes param_array_set() to not use arr->max as nump
argument of param_array. If arr->max is used as nump and the configuration variable is exported writeable in the syfs, the size of the array will be limited by the smallest number of elements specified. One side effect is that as the actual number of elements is not recorded anymore when nump is NULL, all elements should be printed when referencing the corresponding sysfs node. I don't think that will cause any problem.
kernel/params.c +2 -1
@@ -302,9 +302,10 @@ int param_array(const char *name,int param_array_set (const char *val,struct kernel_param *kp) {struct kparam_array *arr = kp->arg; +unsigned int t;return param_array (kp->name, val,1 , arr->max, arr->elem, - arr->elemsize, arr->set, arr->num ?: &arr->max); + arr->elemsize, arr->set, arr->num ?: &t); }int param_array_get (char *buffer,struct kernel_param *kp)
Quoted 4 lines · Tejun Heo
dp_02_param_array_bug.diff
This is the 2nd patch of 16 patches for devparam.
Quoted 8 lines
This patches fixes
param_array_set()to not usearr->maxas nump
argument ofparam_array. Ifarr->maxis used as nump and the configuration variable is exported writeable in the syfs, the size of the array will be limited by the smallest number of elements specified. One side effect is that as the actual number of elements is not recorded anymore when nump is NULL, all elements should be printed when referencing the corresponding sysfs node. I don't think that will cause any problem.
I thought of this, but I prefer to see this fixed by another element in the struct kernel_param which is used as "num" if nump is NULL. Although this creates some bloat, it doesn't truncate as mine does, or allow overflows and printing unset values as yours does.
(Printing unset values is usually OK, since before the new parameter stuff, there was no way of telling how many elements had been set. This lead authors to use a magic value for "unset". They no longer need to do this, so we might see them start to rely on that).
Cheers,
Rusty.
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
Hello, Rusty.
Quoted 14 lines · Rusty Russell
Quoted 4 lines · Tejun Heo
dp_02_param_array_bug.diff
This is the 2nd patch of 16 patches for devparam.
Quoted 8 lines
This patches fixes
param_array_set()to not usearr->maxas nump
argument ofparam_array. Ifarr->maxis used as nump and the configuration variable is exported writeable in the syfs, the size of the array will be limited by the smallest number of elements specified. One side effect is that as the actual number of elements is not recorded anymore when nump is NULL, all elements should be printed when referencing the corresponding sysfs node. I don't think that will cause any problem.
Quoted 4 lines
I thought of this, but I prefer to see this fixed by another element in the struct
kernel_paramwhich is used as "num" if nump is NULL. Although this creates some bloat, it doesn't truncate as mine does, or allow overflows and printing unset values as yours does.
The problem is that, in devparam, a devparam_def and accordingly any
wrapping argument structure is shared by more than one users (e.g. a dev paramset_def is used by all devices attached to the particular driver). And, making matters complicated, bus and class paramset_def's can even be accessed concurrently.
As we need to adjust pointers in wrapping structures to point to
specific fields in each allocated paramsets, wrapping arguments are copied and fixed up everytime it's used (so the arg_copy_size and arg_fixups fields in struct device_paramset_def). i.e. wrapping arguments are transient. They can contain extra read-only information to describe the parameter to the driver-model but cannot contain any information the other way around. Consequently, adding num field to struct param_array wouldn't work for devparam.
Quoted 4 lines
(Printing unset values is usually OK, since before the new parameter stuff, there was no way of telling how many elements had been set. This lead authors to use a magic value for "unset". They no longer need to do this, so we might see them start to rely on that).
I think, for a user who's willing to make use of the number of set
elements, requiring to supply the number field is okay.
Signature · 1 line
tejun