From: zijun_hu <[email protected]>
type bool is used to index three arrays in alloc_and_link_pwqs()
it doesn't look like conventional.
it is fixed by using type int to index the relevant arrays.
Signed-off-by: zijun_hu <[email protected]>
---
kernel/workqueue.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index ab3c0dc8c7ed..0c7a16792949 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3917,7 +3917,7 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu,
static int alloc_and_link_pwqs(struct workqueue_struct *wq)
{
- bool highpri = wq->flags & WQ_HIGHPRI;
+ int pool_idx = (wq->flags & WQ_HIGHPRI) ? 1 : 0;
int cpu, ret;
if (!(wq->flags & WQ_UNBOUND)) {
@@ -3931,7 +3931,7 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
struct worker_pool *cpu_pools =
per_cpu(cpu_worker_pools, cpu);
- init_pwq(pwq, wq, &cpu_pools[highpri]);
+ init_pwq(pwq, wq, &cpu_pools[pool_idx]);
mutex_lock(&wq->mutex);
link_pwq(pwq);
@@ -3939,14 +3939,15 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
}
return 0;
} else if (wq->flags & __WQ_ORDERED) {
- ret = apply_workqueue_attrs(wq, ordered_wq_attrs[highpri]);
+ ret = apply_workqueue_attrs(wq, ordered_wq_attrs[pool_idx]);
/* there should only be single pwq for ordering guarantee */
WARN(!ret && (wq->pwqs.next != &wq->dfl_pwq->pwqs_node ||
wq->pwqs.prev != &wq->dfl_pwq->pwqs_node),
"ordering guarantee broken for workqueue %s\n", wq->name);
return ret;
} else {
- return apply_workqueue_attrs(wq, unbound_std_wq_attrs[highpri]);
+ return apply_workqueue_attrs(wq,
+ unbound_std_wq_attrs[pool_idx]);
}
}
--
1.9.1
Hello,
On Wed, Sep 06, 2017 at 11:34:14AM +0800, zijun_hu wrote:
> From: zijun_hu <[email protected]>
>
> type bool is used to index three arrays in alloc_and_link_pwqs()
> it doesn't look like conventional.
>
> it is fixed by using type int to index the relevant arrays.
bool is a uint type which can be either 0 or 1. I don't see what the
benefit of this patch is.q
Thanks.
--
tejun
On 2017/9/6 22:33, Tejun Heo wrote:
> Hello,
>
> On Wed, Sep 06, 2017 at 11:34:14AM +0800, zijun_hu wrote:
>> From: zijun_hu <[email protected]>
>>
>> type bool is used to index three arrays in alloc_and_link_pwqs()
>> it doesn't look like conventional.
>>
>> it is fixed by using type int to index the relevant arrays.
>
> bool is a uint type which can be either 0 or 1. I don't see what the
> benefit of this patch is.q
>
bool is NOT a uint type now, it is a new type introduced by gcc, it is
rather different with "typedef int bool" historically
see following code segments for more info about type bool
bool v = 0x10;
printf("v = %d\n", v);
the output is v = 1.
it maybe cause a invalid array index if bool is represented as uint
bool highpri = wq->flags & WQ_HIGHPRI; WQ_HIGHPRI = 1 << 4,
@highpri maybe 16, but the number of array elements is 2.
bool is a logic value, the valid value is true or false.
indexing array by type bool is not a good program custom
it is more extendable to use type int, type bool maybe is improper if the number of
array elements is extended to more than 2 in future
besides, the relevant array is indexed by type int in many other places of the
same source file. this patch can keep consistency
>
On Thu, Sep 07, 2017 at 12:04:59AM +0800, zijun_hu wrote:
> On 2017/9/6 22:33, Tejun Heo wrote:
> > Hello,
> >
> > On Wed, Sep 06, 2017 at 11:34:14AM +0800, zijun_hu wrote:
> >> From: zijun_hu <[email protected]>
> >>
> >> type bool is used to index three arrays in alloc_and_link_pwqs()
> >> it doesn't look like conventional.
> >>
> >> it is fixed by using type int to index the relevant arrays.
> >
> > bool is a uint type which can be either 0 or 1. I don't see what the
> > benefit of this patch is.q
> >
> bool is NOT a uint type now, it is a new type introduced by gcc, it is
> rather different with "typedef int bool" historically
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n815.htm
Because C has existed for so long without a Boolean type, however, the
new standard must coexist with the old remedies. Therefore, the type
name is taken from the reserved identifier space. To maintain
orthogonal promotion rules, the Boolean type is defined as an unsigned
integer type capable of representing the values 0 and 1. The more
conventional names for the type and its values are then made available
only with the inclusion of the <stdbool.h> header. In addition, the
header defines a feature test macro to aid in integrating new code
with old code that defines its own Boolean type.
--
tejun
On 2017/9/7 0:40, Tejun Heo wrote:
> On Thu, Sep 07, 2017 at 12:04:59AM +0800, zijun_hu wrote:
>> On 2017/9/6 22:33, Tejun Heo wrote:
>>> Hello,
>>>
>>> On Wed, Sep 06, 2017 at 11:34:14AM +0800, zijun_hu wrote:
>>>> From: zijun_hu <[email protected]>
>>>>
>>>> type bool is used to index three arrays in alloc_and_link_pwqs()
>>>> it doesn't look like conventional.
>>>>
>>>> it is fixed by using type int to index the relevant arrays.
>>>
>>> bool is a uint type which can be either 0 or 1. I don't see what the
>>> benefit of this patch is.q
>>>
>> bool is NOT a uint type now, it is a new type introduced by gcc, it is
>> rather different with "typedef int bool" historically
>
> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n815.htm
>
> Because C has existed for so long without a Boolean type, however, the
> new standard must coexist with the old remedies. Therefore, the type
> name is taken from the reserved identifier space. To maintain
> orthogonal promotion rules, the Boolean type is defined as an unsigned
> integer type capable of representing the values 0 and 1. The more
> conventional names for the type and its values are then made available
> only with the inclusion of the <stdbool.h> header. In addition, the
> header defines a feature test macro to aid in integrating new code
> with old code that defines its own Boolean type.
>
in this case, i think type int is more suitable than bool in aspects of
extendibility, program custom and consistency.
On Thu, Sep 07, 2017 at 01:07:23AM +0800, zijun_hu wrote:
> in this case, i think type int is more suitable than bool in aspects of
> extendibility, program custom and consistency.
Please stop.
--
tejun