2015-12-11 12:09:05

by SF Markus Elfring

[permalink] [raw]
Subject: Source code review around jump label usage

Hello,

I have tried another specific analysis out on the source files
of "Linux next-20151211" with help of the software "Coccinelle 1.0.4".
I have taken a more detailed look on the use of the goto statement
and corresponding jump labels.

Can statistics like the following support software evolution
and further constructive considerations?

╔═════════════════════════════════════════╤═══════════╗
║ target │ incidence ║
╠═════════════════════════════════════════╪═══════════╣
║ out │ 9782 ║
║ done │ 1344 ║
║ exit │ 950 ║
║ out_unlock │ 538 ║
║ unlock │ 509 ║
║ bail │ 486 ║
║ error │ 418 ║
║ retry │ 414 ║
║ err │ 400 ║
║ end │ 332 ║
║ … │ … ║
║ abts_pending │ 1 ║
║ abts_err │ 1 ║
║ absolute_address │ 1 ║
║ abort2 │ 1 ║
║ abort_fail │ 1 ║
║ abort_end │ 1 ║
║ abituguru_probe_error │ 1 ║
║ abituguru_detect_no_pwms_exit │ 1 ║
║ abituguru_detect_bank1_sensor_type_exit │ 1 ║
╚═════════════════════════════════════════╧═══════════╝


How often are different jump targets used within function implementations?
(Functions without jump labels were not searched for this analysis approach.)

╔═════════╤═══════════╗
║ counter │ incidence ║
╠═════════╪═══════════╣
║ 1 │ 18442 ║
║ 2 │ 2002 ║
║ 3 │ 356 ║
║ 4 │ 106 ║
║ 5 │ 31 ║
║ 6 │ 7 ║
║ 7 │ 2 ║
║ 8 │ 3 ║
╚═════════╧═══════════╝


How does the text length distribution look like for the used jump targets?

╔════════╤═══════════╗
║ length │ incidence ║
╠════════╪═══════════╣
║ 1 │ 2 ║
║ 2 │ 29 ║
║ 3 │ 10640 ║
║ 4 │ 3564 ║
║ 5 │ 1714 ║
║ 6 │ 1162 ║
║ 7 │ 1245 ║
║ 8 │ 881 ║
║ 9 │ 787 ║
║ 10 │ 1252 ║
║ … │ … ║
║ 35 │ 4 ║
║ 36 │ 1 ║
║ 37 │ 2 ║
║ 38 │ 1 ║
║ 39 │ 1 ║
╚════════╧═══════════╝


How often are jump targets called within specific function implementations?

╔══════════════════════════╤═════════════════════════════════════════╤══════╤══════════════════════╤═════════╗
║ function │ source file │ line │ go to │ counter ║
╠══════════════════════════╪═════════════════════════════════════════╪══════╪══════════════════════╪═════════╣
║ do_ipv6_setsockopt │ net/ipv6/ipv6_sockglue.c │ 140 │ e_inval │ 52 ║
║ dvb_register │ drivers/media/pci/cx88/cx88-dvb.c │ 1005 │ frontend_detach │ 43 ║
║ dvb_init │ drivers/media/pci/saa7134/saa7134-dvb.c │ 1210 │ detach_frontend │ 40 ║
║ gdbstub_single_step │ arch/mn10300/kernel/gdb-stub.c │ 491 │ fault │ 38 ║
║ uinput_ioctl_handler │ drivers/input/misc/uinput.c │ 701 │ out │ 32 ║
║ … │ … │ … │ … │ … ║
║ kvm_vm_compat_ioctl │ virt/kvm/kvm_main.c │ 2916 │ out │ 1 ║
║ kvm_vm_ioctl │ virt/kvm/kvm_main.c │ 2742 │ out_free_irq_routing │ 1 ║
║ kvm_vm_ioctl_create_vcpu │ virt/kvm/kvm_main.c │ 2257 │ vcpu_destroy │ 1 ║
╚══════════════════════════╧═════════════════════════════════════════╧══════╧══════════════════════╧═════════╝


Do any of these numbers indicate update candidates which correspond to the
"one error jump label bug" symptom that is mentioned in the Linux coding
style documentation?

Regards,
Markus


2015-12-11 12:15:00

by Julia Lawall

[permalink] [raw]
Subject: Re: Source code review around jump label usage

> Do any of these numbers indicate update candidates which correspond to the
> "one error jump label bug" symptom that is mentioned in the Linux coding
> style documentation?

I don't think that numbers could indicate that. The point of that is a
single label followed by a bunch of ifs, or by calls to functions that
perform tests on input validity. That is, it is the content of the code
that causes the problem, not its size. Dan also discourages the use of
labels like out, that don't indicate anything about anything, or
kmalloc_err, which don't indicate anything about what happens at the label
target.

julia

2015-12-11 12:49:10

by Dan Carpenter

[permalink] [raw]
Subject: Re: Source code review around jump label usage

I hate out labels but a lot of people like them and they're not
prohibited by kernel style. I only complain about them when they
introduce bugs.

regards,
dan carpenter

2015-12-11 18:00:32

by Christophe JAILLET

[permalink] [raw]
Subject: Re: Source code review around jump label usage

Le 11/12/2015 13:08, SF Markus Elfring a écrit :
> How does the text length distribution look like for the used jump targets?
>
> ╔════════╤═══════════╗
> ║ length │ incidence ║
> ╠════════╪═══════════╣
> ║ 1 │ 2 ║
> ║ 2 │ 29 ║
> ║ 3 │ 10640 ║
> ║ 4 │ 3564 ║
> ║ 5 │ 1714 ║
> ║ 6 │ 1162 ║
> ║ 7 │ 1245 ║
> ║ 8 │ 881 ║
> ║ 9 │ 787 ║
> ║ 10 │ 1252 ║
> ║ … │ … ║
> ║ 35 │ 4 ║
> ║ 36 │ 1 ║
> ║ 37 │ 2 ║
> ║ 38 │ 1 ║
> ║ 39 │ 1 ║
> ╚════════╧═══════════╝
>

Maybe having a look at the 1 or 2 chars long labels would make sense.
They are likely to be too short for being of any use.

IMHO, too long labels may also reduce readability.

Best regards,
CJ

2015-12-11 18:19:55

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] block: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 19:12:34 +0100

A few update suggestions were taken into account from static
source code analysis.

Markus Elfring (2):
zram: Less checks in zram_bvec_write() after error detection
z2ram: Delete a jump label in z2_init()

drivers/block/z2ram.c | 4 +---
drivers/block/zram/zram_drv.c | 26 +++++++++++++-------------
2 files changed, 14 insertions(+), 16 deletions(-)

--
2.6.3

2015-12-11 18:24:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

From: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 18:20:59 +0100

This issue was detected by using the Coccinelle software.

A few checks could be repeated by the zram_bvec_write() function
at two places even if the passed variables contained a null pointer.

* This implementation detail could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Let us return directly if a memory allocation failed.

* Drop unnecessary initialisations for the variables "uncmem"
and "zstrm" then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/block/zram/zram_drv.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 47915d7..69d7fcd 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
size_t clen;
unsigned long handle;
struct page *page;
- unsigned char *user_mem, *cmem, *src, *uncmem = NULL;
+ unsigned char *user_mem, *cmem, *src, *uncmem;
struct zram_meta *meta = zram->meta;
- struct zcomp_strm *zstrm = NULL;
+ struct zcomp_strm *zstrm;
unsigned long alloced_pages;

page = bvec->bv_page;
@@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
* before to write the changes.
*/
uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
- if (!uncmem) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!uncmem)
+ return -ENOMEM;
ret = zram_decompress_page(zram, uncmem, index);
if (ret)
- goto out;
+ goto free_uncmem;
}

zstrm = zcomp_strm_find(zram->comp);
@@ -696,7 +694,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,

atomic64_inc(&zram->stats.zero_pages);
ret = 0;
- goto out;
+ goto check_strm;
}

ret = zcomp_compress(zram->comp, zstrm, uncmem, &clen);
@@ -708,7 +706,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,

if (unlikely(ret)) {
pr_err("Compression failed! err=%d\n", ret);
- goto out;
+ goto check_strm;
}
src = zstrm->buffer;
if (unlikely(clen > max_zpage_size)) {
@@ -722,7 +720,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
pr_err("Error allocating memory for compressed page: %u, size=%zu\n",
index, clen);
ret = -ENOMEM;
- goto out;
+ goto check_strm;
}

alloced_pages = zs_get_total_pages(meta->mem_pool);
@@ -731,7 +729,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
if (zram->limit_pages && alloced_pages > zram->limit_pages) {
zs_free(meta->mem_pool, handle);
ret = -ENOMEM;
- goto out;
+ goto check_strm;
}

cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO);
@@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
/* Update stats */
atomic64_add(clen, &zram->stats.compr_data_size);
atomic64_inc(&zram->stats.pages_stored);
-out:
+check_strm:
if (zstrm)
zcomp_strm_release(zram->comp, zstrm);
- if (is_partial_io(bvec))
+ if (is_partial_io(bvec)) {
+free_uncmem:
kfree(uncmem);
+ }
return ret;
}

--
2.6.3

2015-12-11 18:26:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] z2ram: Delete a jump label in z2_init()

From: Markus Elfring <[email protected]>
Date: Fri, 11 Dec 2015 18:48:14 +0100

This issue was detected by using the Coccinelle software.

* Let us return directly if a call of the function "register_blkdev" failed.

* Remove the jump label "err" then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/block/z2ram.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 968f9e5..b07581d 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -345,9 +345,8 @@ z2_init(void)
if (!MACH_IS_AMIGA)
return -ENODEV;

- ret = -EBUSY;
if (register_blkdev(Z2RAM_MAJOR, DEVICE_NAME))
- goto err;
+ return -EBUSY;

ret = -ENOMEM;
z2ram_gendisk = alloc_disk(1);
@@ -374,7 +373,6 @@ out_queue:
put_disk(z2ram_gendisk);
out_disk:
unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
-err:
return ret;
}

--
2.6.3

2015-12-12 09:16:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] uinput: Rename a jump label in uinput_ioctl_handler()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 10:06:00 +0100

This issue was detected by using the Coccinelle software.

Choose a jump label according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 5adbced..466f62d 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -717,7 +717,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
if (!udev->dev) {
retval = uinput_allocate_device(udev);
if (retval)
- goto out;
+ goto unlock;
}

switch (cmd) {
@@ -725,82 +725,82 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
if (put_user(UINPUT_VERSION,
(unsigned int __user *)p))
retval = -EFAULT;
- goto out;
+ goto unlock;

case UI_DEV_CREATE:
retval = uinput_create_device(udev);
- goto out;
+ goto unlock;

case UI_DEV_DESTROY:
uinput_destroy_device(udev);
- goto out;
+ goto unlock;

case UI_SET_EVBIT:
retval = uinput_set_bit(arg, evbit, EV_MAX);
- goto out;
+ goto unlock;

case UI_SET_KEYBIT:
retval = uinput_set_bit(arg, keybit, KEY_MAX);
- goto out;
+ goto unlock;

case UI_SET_RELBIT:
retval = uinput_set_bit(arg, relbit, REL_MAX);
- goto out;
+ goto unlock;

case UI_SET_ABSBIT:
retval = uinput_set_bit(arg, absbit, ABS_MAX);
- goto out;
+ goto unlock;

case UI_SET_MSCBIT:
retval = uinput_set_bit(arg, mscbit, MSC_MAX);
- goto out;
+ goto unlock;

case UI_SET_LEDBIT:
retval = uinput_set_bit(arg, ledbit, LED_MAX);
- goto out;
+ goto unlock;

case UI_SET_SNDBIT:
retval = uinput_set_bit(arg, sndbit, SND_MAX);
- goto out;
+ goto unlock;

case UI_SET_FFBIT:
retval = uinput_set_bit(arg, ffbit, FF_MAX);
- goto out;
+ goto unlock;

case UI_SET_SWBIT:
retval = uinput_set_bit(arg, swbit, SW_MAX);
- goto out;
+ goto unlock;

case UI_SET_PROPBIT:
retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX);
- goto out;
+ goto unlock;

case UI_SET_PHYS:
if (udev->state == UIST_CREATED) {
retval = -EINVAL;
- goto out;
+ goto unlock;
}

phys = strndup_user(p, 1024);
if (IS_ERR(phys)) {
retval = PTR_ERR(phys);
- goto out;
+ goto unlock;
}

kfree(udev->dev->phys);
udev->dev->phys = phys;
- goto out;
+ goto unlock;

case UI_BEGIN_FF_UPLOAD:
retval = uinput_ff_upload_from_user(p, &ff_up);
if (retval)
- goto out;
+ goto unlock;

req = uinput_request_find(udev, ff_up.request_id);
if (!req || req->code != UI_FF_UPLOAD ||
!req->u.upload.effect) {
retval = -EINVAL;
- goto out;
+ goto unlock;
}

ff_up.retval = 0;
@@ -811,60 +811,60 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
memset(&ff_up.old, 0, sizeof(struct ff_effect));

retval = uinput_ff_upload_to_user(p, &ff_up);
- goto out;
+ goto unlock;

case UI_BEGIN_FF_ERASE:
if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
retval = -EFAULT;
- goto out;
+ goto unlock;
}

req = uinput_request_find(udev, ff_erase.request_id);
if (!req || req->code != UI_FF_ERASE) {
retval = -EINVAL;
- goto out;
+ goto unlock;
}

ff_erase.retval = 0;
ff_erase.effect_id = req->u.effect_id;
if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) {
retval = -EFAULT;
- goto out;
+ goto unlock;
}

- goto out;
+ goto unlock;

case UI_END_FF_UPLOAD:
retval = uinput_ff_upload_from_user(p, &ff_up);
if (retval)
- goto out;
+ goto unlock;

req = uinput_request_find(udev, ff_up.request_id);
if (!req || req->code != UI_FF_UPLOAD ||
!req->u.upload.effect) {
retval = -EINVAL;
- goto out;
+ goto unlock;
}

req->retval = ff_up.retval;
uinput_request_done(udev, req);
- goto out;
+ goto unlock;

case UI_END_FF_ERASE:
if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
retval = -EFAULT;
- goto out;
+ goto unlock;
}

req = uinput_request_find(udev, ff_erase.request_id);
if (!req || req->code != UI_FF_ERASE) {
retval = -EINVAL;
- goto out;
+ goto unlock;
}

req->retval = ff_erase.retval;
uinput_request_done(udev, req);
- goto out;
+ goto unlock;
}

size = _IOC_SIZE(cmd);
@@ -874,15 +874,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
case UI_GET_SYSNAME(0):
if (udev->state != UIST_CREATED) {
retval = -ENOENT;
- goto out;
+ goto unlock;
}
name = dev_name(&udev->dev->dev);
retval = uinput_str_to_user(p, name, size);
- goto out;
+ goto unlock;
}

retval = -EINVAL;
- out:
+ unlock:
mutex_unlock(&udev->mutex);
return retval;
}
--
2.6.3

2015-12-12 14:30:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/7] iSCSI-target: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:25:20 +0100

Some update suggestions were taken into account from static
source code analysis.

Markus Elfring (7):
Use a variable initialisation in iscsi_set_default_param() directly
Less checks in iscsi_set_default_param() after error detection
Delete an unnecessary variable initialisation in iscsi_create_default_params()
Make a variable initialisation a bit more obvious in iscsi_create_default_params()
Rename a jump label in iscsi_create_default_params()
Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support()
Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()

drivers/target/iscsi/iscsi_target_parameters.c | 100 ++++++++++++-------------
1 file changed, 47 insertions(+), 53 deletions(-)

--
2.6.3

2015-12-12 14:35:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100

Omit the unnecessary setting to a null pointer for the variable "param"
at the beginning of the function "iscsi_set_default_param"
because it can be directly initialized with the return value
from the function "kzalloc".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 3a1f9a7..0a8bd3f 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
char *name, char *value, u8 phase, u8 scope, u8 sender,
u16 type_range, u8 use)
{
- struct iscsi_param *param = NULL;
+ struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL);

- param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
if (!param) {
pr_err("Unable to allocate memory for parameter.\n");
goto out;
--
2.6.3

2015-12-12 14:37:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/7] iscsi-target: Less checks in iscsi_set_default_param() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 12:50:10 +0100

This issue was detected by using the Coccinelle software.

A sanity check would be performed by the iscsi_set_default_param() function
even if it is known already that the passed variable contained
a null pointer.

* This implementation detail could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Let us return directly if a call of the function "kzalloc" failed.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 0a8bd3f..15b2618 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -131,20 +131,20 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para

if (!param) {
pr_err("Unable to allocate memory for parameter.\n");
- goto out;
+ return NULL;
}
INIT_LIST_HEAD(&param->p_list);

param->name = kstrdup(name, GFP_KERNEL);
if (!param->name) {
pr_err("Unable to allocate memory for parameter name.\n");
- goto out;
+ goto free_param;
}

param->value = kstrdup(value, GFP_KERNEL);
if (!param->value) {
pr_err("Unable to allocate memory for parameter value.\n");
- goto out;
+ goto free_name;
}

param->phase = phase;
@@ -182,18 +182,17 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
default:
pr_err("Unknown type_range 0x%02x\n",
param->type_range);
- goto out;
+ goto free_value;
}
list_add_tail(&param->p_list, &param_list->param_list);

return param;
-out:
- if (param) {
- kfree(param->value);
- kfree(param->name);
- kfree(param);
- }
-
+free_value:
+ kfree(param->value);
+free_name:
+ kfree(param->name);
+free_param:
+ kfree(param);
return NULL;
}

--
2.6.3

2015-12-12 14:40:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/7] iscsi-target: Delete an unnecessary variable initialisation in iscsi_create_default_params()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:20:08 +0100

The variable "param" will eventually be set to an appropriate pointer
from a call of the iscsi_set_default_param() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 15b2618..e0b173d 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -199,7 +199,7 @@ free_param:
/* #warning Add extension keys */
int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
{
- struct iscsi_param *param = NULL;
+ struct iscsi_param *param;
struct iscsi_param_list *pl;

pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
--
2.6.3

2015-12-12 14:41:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:44:06 +0100

The variable "pl" was declared and immediately assigned a return value
from a function call in a separate statement.

* Let us express the desired variable initialisation directly.

* Avoid the repetition of the data type specification for the
involved memory allocation according to the Linux coding
style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index e0b173d..3f3842f 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -200,9 +200,8 @@ free_param:
int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
{
struct iscsi_param *param;
- struct iscsi_param_list *pl;
+ struct iscsi_param_list *pl = kzalloc(sizeof(*pl), GFP_KERNEL);

- pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
if (!pl) {
pr_err("Unable to allocate memory for"
" struct iscsi_param_list.\n");
--
2.6.3

2015-12-12 14:42:48

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/7] iscsi-target: Rename a jump label in iscsi_create_default_params()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 14:12:50 +0100

This issue was detected by using the Coccinelle software.

Choose a jump label according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 64 +++++++++++++-------------
1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 3f3842f..29ecf29 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -225,185 +225,185 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
PHASE_SECURITY, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_AUTH, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, HEADERDIGEST, INITIAL_HEADERDIGEST,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_DIGEST, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, DATADIGEST, INITIAL_DATADIGEST,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_DIGEST, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, MAXCONNECTIONS,
INITIAL_MAXCONNECTIONS, PHASE_OPERATIONAL,
SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, SENDTARGETS, INITIAL_SENDTARGETS,
PHASE_FFP0, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
TYPERANGE_UTF8, 0);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, TARGETNAME, INITIAL_TARGETNAME,
PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_ISCSINAME, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, INITIATORNAME,
INITIAL_INITIATORNAME, PHASE_DECLARATIVE,
SCOPE_SESSION_WIDE, SENDER_INITIATOR,
TYPERANGE_ISCSINAME, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, TARGETALIAS, INITIAL_TARGETALIAS,
PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
TYPERANGE_UTF8, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, INITIATORALIAS,
INITIAL_INITIATORALIAS, PHASE_DECLARATIVE,
SCOPE_SESSION_WIDE, SENDER_INITIATOR, TYPERANGE_UTF8,
USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, TARGETADDRESS,
INITIAL_TARGETADDRESS, PHASE_DECLARATIVE,
SCOPE_SESSION_WIDE, SENDER_TARGET,
TYPERANGE_TARGETADDRESS, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, TARGETPORTALGROUPTAG,
INITIAL_TARGETPORTALGROUPTAG,
PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
TYPERANGE_0_TO_65535, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, INITIALR2T, INITIAL_INITIALR2T,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, IMMEDIATEDATA,
INITIAL_IMMEDIATEDATA, PHASE_OPERATIONAL,
SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_AND,
USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, MAXXMITDATASEGMENTLENGTH,
INITIAL_MAXXMITDATASEGMENTLENGTH,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, MAXRECVDATASEGMENTLENGTH,
INITIAL_MAXRECVDATASEGMENTLENGTH,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, MAXBURSTLENGTH,
INITIAL_MAXBURSTLENGTH, PHASE_OPERATIONAL,
SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, FIRSTBURSTLENGTH,
INITIAL_FIRSTBURSTLENGTH,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, DEFAULTTIME2WAIT,
INITIAL_DEFAULTTIME2WAIT,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, DEFAULTTIME2RETAIN,
INITIAL_DEFAULTTIME2RETAIN,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, MAXOUTSTANDINGR2T,
INITIAL_MAXOUTSTANDINGR2T,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, DATAPDUINORDER,
INITIAL_DATAPDUINORDER, PHASE_OPERATIONAL,
SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_OR,
USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, DATASEQUENCEINORDER,
INITIAL_DATASEQUENCEINORDER,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, ERRORRECOVERYLEVEL,
INITIAL_ERRORRECOVERYLEVEL,
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_0_TO_2, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, SESSIONTYPE, INITIAL_SESSIONTYPE,
PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
TYPERANGE_SESSIONTYPE, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, IFMARKER, INITIAL_IFMARKER,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, OFMARKER, INITIAL_OFMARKER,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_UTF8, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_UTF8, USE_INITIAL_ONLY);
if (!param)
- goto out;
+ goto release_list;

/*
* Extra parameters for ISER from RFC-5046
@@ -412,25 +412,25 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
TYPERANGE_BOOL_AND, USE_LEADING_ONLY);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, INITIATORRECVDATASEGMENTLENGTH,
INITIAL_INITIATORRECVDATASEGMENTLENGTH,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

param = iscsi_set_default_param(pl, TARGETRECVDATASEGMENTLENGTH,
INITIAL_TARGETRECVDATASEGMENTLENGTH,
PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
TYPERANGE_512_TO_16777215, USE_ALL);
if (!param)
- goto out;
+ goto release_list;

*param_list_ptr = pl;
return 0;
-out:
+release_list:
iscsi_release_param_list(pl);
return -1;
}
--
2.6.3

2015-12-12 14:43:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/7] iscsi-target: Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 14:34:26 +0100

The variables "tmp1" and "tmp2" will eventually be set to appropriate
pointers from a call of the strchr() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 29ecf29..53e3345 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -920,7 +920,7 @@ static char *iscsi_check_valuelist_for_support(
struct iscsi_param *param,
char *value)
{
- char *tmp1 = NULL, *tmp2 = NULL;
+ char *tmp1, *tmp2;
char *acceptor_values = NULL, *proposer_values = NULL;

acceptor_values = param->value;
--
2.6.3

2015-12-12 14:45:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 7/7] iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()

From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:04:57 +0100

The variable "acceptor_values" and "proposer_values" were initialized
by null pointers and immediately assigned values from input parameters
by separate statements.
Let us express the desired variable initialisations directly.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/target/iscsi/iscsi_target_parameters.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 53e3345..fb6fd34 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -921,10 +921,7 @@ static char *iscsi_check_valuelist_for_support(
char *value)
{
char *tmp1, *tmp2;
- char *acceptor_values = NULL, *proposer_values = NULL;
-
- acceptor_values = param->value;
- proposer_values = value;
+ char *acceptor_values = param->value, *proposer_values = value;

do {
if (!proposer_values)
--
2.6.3

2015-12-12 14:46:05

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()



On Sat, 12 Dec 2015, SF Markus Elfring wrote:

> From: Markus Elfring <[email protected]>
> Date: Sat, 12 Dec 2015 13:44:06 +0100
>
> The variable "pl" was declared and immediately assigned a return value
> from a function call in a separate statement.
>
> * Let us express the desired variable initialisation directly.
>
> * Avoid the repetition of the data type specification for the
> involved memory allocation according to the Linux coding
> style convention.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/target/iscsi/iscsi_target_parameters.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
> index e0b173d..3f3842f 100644
> --- a/drivers/target/iscsi/iscsi_target_parameters.c
> +++ b/drivers/target/iscsi/iscsi_target_parameters.c
> @@ -200,9 +200,8 @@ free_param:
> int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
> {
> struct iscsi_param *param;
> - struct iscsi_param_list *pl;
> + struct iscsi_param_list *pl = kzalloc(sizeof(*pl), GFP_KERNEL);
>
> - pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);

I don't see the benefit of this change, and the pattern assignment ->
failure test becomes more obscure.

julia

> if (!pl) {
> pr_err("Unable to allocate memory for"
> " struct iscsi_param_list.\n");
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-12-12 15:02:25

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()

>> @@ -200,9 +200,8 @@ free_param:
>> int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
>> {
>> struct iscsi_param *param;
>> - struct iscsi_param_list *pl;
>> + struct iscsi_param_list *pl = kzalloc(sizeof(*pl), GFP_KERNEL);
>>
>> - pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
>
> I don't see the benefit of this change, and the pattern assignment ->
> failure test becomes more obscure.

Are there any more software developers who prefer to specify
such a variable initialisation on a single line?

Does the proposed small source code reduction matter for you?

Regards,
Markus

2015-12-12 17:18:03

by walter harms

[permalink] [raw]
Subject: Re: [PATCH 7/7] iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()



Am 12.12.2015 15:45, schrieb SF Markus Elfring:
> From: Markus Elfring <[email protected]>
> Date: Sat, 12 Dec 2015 15:04:57 +0100
>
> The variable "acceptor_values" and "proposer_values" were initialized
> by null pointers and immediately assigned values from input parameters
> by separate statements.
> Let us express the desired variable initialisations directly.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/target/iscsi/iscsi_target_parameters.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
> index 53e3345..fb6fd34 100644
> --- a/drivers/target/iscsi/iscsi_target_parameters.c
> +++ b/drivers/target/iscsi/iscsi_target_parameters.c
> @@ -921,10 +921,7 @@ static char *iscsi_check_valuelist_for_support(
> char *value)
> {
> char *tmp1, *tmp2;
> - char *acceptor_values = NULL, *proposer_values = NULL;
> -
> - acceptor_values = param->value;
> - proposer_values = value;
> + char *acceptor_values = param->value, *proposer_values = value;
>

I do not thing that this is a good idea,
i find the first version more readable
but you are right the NULL can be removed.

just my 2 cents,

re,
wh



> do {
> if (!proposer_values)

2015-12-12 19:49:59

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly

On Sat, Dec 12, 2015 at 03:34:50PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 12 Dec 2015 11:36:02 +0100
>
> Omit the unnecessary setting to a null pointer for the variable "param"
> at the beginning of the function "iscsi_set_default_param"
> because it can be directly initialized with the return value
> from the function "kzalloc".
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/target/iscsi/iscsi_target_parameters.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
> index 3a1f9a7..0a8bd3f 100644
> --- a/drivers/target/iscsi/iscsi_target_parameters.c
> +++ b/drivers/target/iscsi/iscsi_target_parameters.c
> @@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
> char *name, char *value, u8 phase, u8 scope, u8 sender,
> u16 type_range, u8 use)
> {
> - struct iscsi_param *param = NULL;
> + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL);
>
> - param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
> if (!param) {
> pr_err("Unable to allocate memory for parameter.\n");
> goto out;

It's better to just get rid of the initialization but leave the
kzalloc() as-is for two reasons.

1) Initializer code normally contains more bugs per line than other
code. I am thinking about dereferencing pointers before checking
for NULL or not checking the allocation for failure.

2) It puts a blank line between the allocation and the check for
failure. It's like a new paragraph. The allocation and the check
should be next to each other.

regards,
dan carpenter

2015-12-12 21:23:14

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly

>> @@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
>> char *name, char *value, u8 phase, u8 scope, u8 sender,
>> u16 type_range, u8 use)
>> {
>> - struct iscsi_param *param = NULL;
>> + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL);
>>
>> - param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
>> if (!param) {
>> pr_err("Unable to allocate memory for parameter.\n");
>> goto out;
>
> It's better to just get rid of the initialization but leave the
> kzalloc() as-is for two reasons.
>
> 1) Initializer code normally contains more bugs per line than other
> code. I am thinking about dereferencing pointers before checking
> for NULL or not checking the allocation for failure.

I can follow your concerns a bit.


> 2) It puts a blank line between the allocation and the check for failure.

Is there a target conflict between "convenient" variable initialisation
in the declaration section and the function outline that seems to be checked
by the script "checkpatch.pl" to some degree while corresponding preferences
or recommendations are not mentioned in the document "CodingStyle"?


> It's like a new paragraph.

I do not see the separation in a strict way so far.


> The allocation and the check should be next to each other.

I find that these actions are still close enough in the discussed use case.

Regards,
Markus

2015-12-12 22:23:33

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] uinput: Rename a jump label in uinput_ioctl_handler()

Hi Markus,

On Sat, Dec 12, 2015 at 10:16:34AM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 12 Dec 2015 10:06:00 +0100
>
> This issue was detected by using the Coccinelle software.
>
> Choose a jump label according to the current Linux coding style convention.

While I am mildly curious where you found this Coccinelle script
complaining about label names I find the current name is perfectly fine.

Thanks.

>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++-----------------------
> 1 file changed, 33 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index 5adbced..466f62d 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -717,7 +717,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
> if (!udev->dev) {
> retval = uinput_allocate_device(udev);
> if (retval)
> - goto out;
> + goto unlock;
> }
>
> switch (cmd) {
> @@ -725,82 +725,82 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
> if (put_user(UINPUT_VERSION,
> (unsigned int __user *)p))
> retval = -EFAULT;
> - goto out;
> + goto unlock;
>
> case UI_DEV_CREATE:
> retval = uinput_create_device(udev);
> - goto out;
> + goto unlock;
>
> case UI_DEV_DESTROY:
> uinput_destroy_device(udev);
> - goto out;
> + goto unlock;
>
> case UI_SET_EVBIT:
> retval = uinput_set_bit(arg, evbit, EV_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_KEYBIT:
> retval = uinput_set_bit(arg, keybit, KEY_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_RELBIT:
> retval = uinput_set_bit(arg, relbit, REL_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_ABSBIT:
> retval = uinput_set_bit(arg, absbit, ABS_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_MSCBIT:
> retval = uinput_set_bit(arg, mscbit, MSC_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_LEDBIT:
> retval = uinput_set_bit(arg, ledbit, LED_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_SNDBIT:
> retval = uinput_set_bit(arg, sndbit, SND_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_FFBIT:
> retval = uinput_set_bit(arg, ffbit, FF_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_SWBIT:
> retval = uinput_set_bit(arg, swbit, SW_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_PROPBIT:
> retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX);
> - goto out;
> + goto unlock;
>
> case UI_SET_PHYS:
> if (udev->state == UIST_CREATED) {
> retval = -EINVAL;
> - goto out;
> + goto unlock;
> }
>
> phys = strndup_user(p, 1024);
> if (IS_ERR(phys)) {
> retval = PTR_ERR(phys);
> - goto out;
> + goto unlock;
> }
>
> kfree(udev->dev->phys);
> udev->dev->phys = phys;
> - goto out;
> + goto unlock;
>
> case UI_BEGIN_FF_UPLOAD:
> retval = uinput_ff_upload_from_user(p, &ff_up);
> if (retval)
> - goto out;
> + goto unlock;
>
> req = uinput_request_find(udev, ff_up.request_id);
> if (!req || req->code != UI_FF_UPLOAD ||
> !req->u.upload.effect) {
> retval = -EINVAL;
> - goto out;
> + goto unlock;
> }
>
> ff_up.retval = 0;
> @@ -811,60 +811,60 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
> memset(&ff_up.old, 0, sizeof(struct ff_effect));
>
> retval = uinput_ff_upload_to_user(p, &ff_up);
> - goto out;
> + goto unlock;
>
> case UI_BEGIN_FF_ERASE:
> if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
> retval = -EFAULT;
> - goto out;
> + goto unlock;
> }
>
> req = uinput_request_find(udev, ff_erase.request_id);
> if (!req || req->code != UI_FF_ERASE) {
> retval = -EINVAL;
> - goto out;
> + goto unlock;
> }
>
> ff_erase.retval = 0;
> ff_erase.effect_id = req->u.effect_id;
> if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) {
> retval = -EFAULT;
> - goto out;
> + goto unlock;
> }
>
> - goto out;
> + goto unlock;
>
> case UI_END_FF_UPLOAD:
> retval = uinput_ff_upload_from_user(p, &ff_up);
> if (retval)
> - goto out;
> + goto unlock;
>
> req = uinput_request_find(udev, ff_up.request_id);
> if (!req || req->code != UI_FF_UPLOAD ||
> !req->u.upload.effect) {
> retval = -EINVAL;
> - goto out;
> + goto unlock;
> }
>
> req->retval = ff_up.retval;
> uinput_request_done(udev, req);
> - goto out;
> + goto unlock;
>
> case UI_END_FF_ERASE:
> if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
> retval = -EFAULT;
> - goto out;
> + goto unlock;
> }
>
> req = uinput_request_find(udev, ff_erase.request_id);
> if (!req || req->code != UI_FF_ERASE) {
> retval = -EINVAL;
> - goto out;
> + goto unlock;
> }
>
> req->retval = ff_erase.retval;
> uinput_request_done(udev, req);
> - goto out;
> + goto unlock;
> }
>
> size = _IOC_SIZE(cmd);
> @@ -874,15 +874,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
> case UI_GET_SYSNAME(0):
> if (udev->state != UIST_CREATED) {
> retval = -ENOENT;
> - goto out;
> + goto unlock;
> }
> name = dev_name(&udev->dev->dev);
> retval = uinput_str_to_user(p, name, size);
> - goto out;
> + goto unlock;
> }
>
> retval = -EINVAL;
> - out:
> + unlock:
> mutex_unlock(&udev->mutex);
> return retval;
> }
> --
> 2.6.3
>

--
Dmitry

2015-12-13 13:48:51

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/7] staging-Lustre: Fine-tuning for some function implementations

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 14:40:14 +0100

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (7):
Delete unnecessary goto statements in six functions
Rename a jump label for ptlrpc_req_finished() calls
Rename a jump label for a kfree(key) call
Delete an unnecessary variable initialisation in mgc_process_recover_log()
Less checks in mgc_process_recover_log() after error detection
A few checks less in mgc_process_recover_log() after error detection
Rename a jump label for module_put() calls

drivers/staging/lustre/lustre/llite/file.c | 26 ++---
drivers/staging/lustre/lustre/llite/lloop.c | 8 +-
drivers/staging/lustre/lustre/llite/namei.c | 13 +--
drivers/staging/lustre/lustre/llite/xattr.c | 20 ++--
drivers/staging/lustre/lustre/mdc/mdc_request.c | 124 ++++++++++-----------
drivers/staging/lustre/lustre/mgc/mgc_request.c | 53 ++++-----
drivers/staging/lustre/lustre/osc/osc_request.c | 52 ++++-----
drivers/staging/lustre/lustre/ptlrpc/llog_client.c | 22 ++--
8 files changed, 152 insertions(+), 166 deletions(-)

--
2.6.3

2015-12-13 13:53:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100

Six goto statements referred to a source code position directly behind them.
Thus omit such unnecessary jumps.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/llite/namei.c | 1 -
drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 -------
2 files changed, 8 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 64db5e8..2113dd4 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
retval = NULL;
else
retval = dentry;
- goto out;
out:
if (req)
ptlrpc_req_finished(req);
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 294c050..920b1e9 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1181,7 +1181,6 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1216,7 +1215,6 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1282,7 +1280,6 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1362,8 +1359,6 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
-
out:
ptlrpc_req_finished(req);
return rc;
@@ -1427,8 +1422,6 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
-
out:
ptlrpc_req_finished(req);
return rc;
--
2.6.3

2015-12-13 13:54:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 10:33:38 +0100

This issue was detected by using the Coccinelle software.

Choose a jump label according to the current Linux coding style convention.
I suggest to improve this implementation detail by the reuse of a script
like the following for the semantic patch language.

@rename_jump_label exists@
identifier work;
type return_type;
@@
return_type work(...)
{
... when any
goto
-out
+finish_request
;
... when any
-out
+finish_request
:
ptlrpc_req_finished(...);
... when any
}

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/llite/file.c | 26 +++++------
drivers/staging/lustre/lustre/llite/namei.c | 12 ++---
drivers/staging/lustre/lustre/llite/xattr.c | 20 ++++----
drivers/staging/lustre/lustre/mdc/mdc_request.c | 54 +++++++++++-----------
drivers/staging/lustre/lustre/osc/osc_request.c | 28 +++++------
drivers/staging/lustre/lustre/ptlrpc/llog_client.c | 22 ++++-----
6 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index 31cd6b3..b94df54 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -427,27 +427,27 @@ static int ll_intent_file_open(struct dentry *dentry, void *lmm,
*/
if (!it_disposition(itp, DISP_OPEN_OPEN) ||
it_open_error(DISP_OPEN_OPEN, itp))
- goto out;
+ goto finish_request;
ll_release_openhandle(inode, itp);
- goto out;
+ goto finish_request;
}

if (it_disposition(itp, DISP_LOOKUP_NEG)) {
rc = -ENOENT;
- goto out;
+ goto finish_request;
}

if (rc != 0 || it_open_error(DISP_OPEN_OPEN, itp)) {
rc = rc ? rc : it_open_error(DISP_OPEN_OPEN, itp);
CDEBUG(D_VFSTRACE, "lock enqueue: err: %d\n", rc);
- goto out;
+ goto finish_request;
}

rc = ll_prep_inode(&inode, req, NULL, itp);
if (!rc && itp->d.lustre.it_lock_mode)
ll_set_lock_data(sbi->ll_md_exp, inode, itp, NULL);

-out:
+finish_request:
ptlrpc_req_finished(req);
ll_intent_drop_lock(itp);

@@ -2900,13 +2900,13 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits)
oit.it_create_mode &= ~M_CHECK_STALE;
if (rc < 0) {
rc = ll_inode_revalidate_fini(inode, rc);
- goto out;
+ goto finish_request;
}

rc = ll_revalidate_it_finish(req, &oit, inode);
if (rc != 0) {
ll_intent_release(&oit);
- goto out;
+ goto finish_request;
}

/* Unlinked? Unhash dentry, so it is not picked up later by
@@ -2946,7 +2946,7 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits)

rc = ll_prep_inode(&inode, req, NULL, NULL);
}
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -3315,25 +3315,25 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
if (body == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

lmmsize = body->eadatasize;
if (lmmsize == 0) /* empty layout */ {
rc = 0;
- goto out;
+ goto finish_request;
}

lmm = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA, lmmsize);
if (lmm == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

lvbdata = libcfs_kvzalloc(lmmsize, GFP_NOFS);
if (lvbdata == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

memcpy(lvbdata, lmm, lmmsize);
@@ -3345,7 +3345,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
lock->l_lvb_len = lmmsize;
unlock_res_and_lock(lock);

-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 2113dd4..7501f70 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -686,7 +686,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
rc = ll_prep_inode(&inode, request, dir->i_sb, it);
if (rc) {
inode = ERR_PTR(rc);
- goto out;
+ goto finish_request;
}

LASSERT(hlist_empty(&inode->i_dentry));
@@ -697,7 +697,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
inode, inode->i_ino, inode->i_generation);
ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
- out:
+ finish_request:
ptlrpc_req_finished(request);
return inode;
}
@@ -960,13 +960,13 @@ static int ll_unlink(struct inode *dir, struct dentry *dentry)
rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
ll_finish_md_op_data(op_data);
if (rc)
- goto out;
+ goto finish_request;

ll_update_times(request, dir);
ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);

rc = ll_objects_destroy(request, dir);
- out:
+ finish_request:
ptlrpc_req_finished(request);
return rc;
}
@@ -1059,11 +1059,11 @@ static int ll_link(struct dentry *old_dentry, struct inode *dir,
err = md_link(sbi->ll_md_exp, op_data, &request);
ll_finish_md_op_data(op_data);
if (err)
- goto out;
+ goto finish_request;

ll_update_times(request, dir);
ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
-out:
+finish_request:
ptlrpc_req_finished(request);
return err;
}
diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 660b8ac..8d3287c 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -390,19 +390,19 @@ getxattr_nocache:
/* only detect the xattr size */
if (size == 0) {
rc = body->eadatasize;
- goto out;
+ goto finish_request;
}

if (size < body->eadatasize) {
CERROR("server bug: replied size %u > %u\n",
body->eadatasize, (int)size);
rc = -ERANGE;
- goto out;
+ goto finish_request;
}

if (body->eadatasize == 0) {
rc = -ENODATA;
- goto out;
+ goto finish_request;
}

/* do not need swab xattr data */
@@ -410,7 +410,7 @@ getxattr_nocache:
body->eadatasize);
if (!xdata) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

memcpy(buffer, xdata, body->eadatasize);
@@ -425,14 +425,14 @@ getxattr_nocache:
(posix_acl_xattr_header *)buffer, rc);
if (IS_ERR(acl)) {
rc = PTR_ERR(acl);
- goto out;
+ goto finish_request;
}

rc = ee_add(&sbi->ll_et, current_pid(), ll_inode2fid(inode),
xattr_type, acl);
if (unlikely(rc < 0)) {
lustre_ext_acl_xattr_free(acl);
- goto out;
+ goto finish_request;
}
}
#endif
@@ -444,7 +444,7 @@ out_xattr:
ll_get_fsname(inode->i_sb, NULL, 0), rc);
sbi->ll_flags &= ~LL_SBI_USER_XATTR;
}
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -555,7 +555,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)

rc = ll_getxattr_common(inode, NULL, buffer, size, OBD_MD_FLXATTRLS);
if (rc < 0)
- goto out;
+ goto finish_request;

if (buffer != NULL) {
struct ll_sb_info *sbi = ll_i2sbi(inode);
@@ -589,7 +589,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)

if (rc2 < 0) {
rc2 = 0;
- goto out;
+ goto finish_request;
} else if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)) {
const int prefix_len = sizeof(XATTR_LUSTRE_PREFIX) - 1;
const size_t name_len = sizeof("lov") - 1;
@@ -608,7 +608,7 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
}
rc2 = total_len;
}
-out:
+finish_request:
ptlrpc_req_finished(request);
rc = rc + rc2;

diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 920b1e9..2a76685 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -92,12 +92,12 @@ static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid)

rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
if (body == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*rootfid = body->fid1;
@@ -105,7 +105,7 @@ static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid)
"root fid="DFID", last_committed=%llu\n",
PFID(rootfid),
lustre_msg_get_last_committed(req->rq_repmsg));
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1084,17 +1084,17 @@ static int mdc_statfs(const struct lu_env *env,
/* check connection error first */
if (imp->imp_connect_error)
rc = imp->imp_connect_error;
- goto out;
+ goto finish_request;
}

msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
if (msfs == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*osfs = *msfs;
-out:
+finish_request:
ptlrpc_req_finished(req);
output:
class_import_put(imp);
@@ -1163,7 +1163,7 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
@@ -1172,7 +1172,7 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
if (req_hpk == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*req_hpk = *hpk;
@@ -1181,7 +1181,7 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1197,7 +1197,7 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
MDS_HSM_CT_REGISTER);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
@@ -1207,7 +1207,7 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
&RMF_MDS_HSM_ARCHIVE);
if (archive_mask == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*archive_mask = archives;
@@ -1215,7 +1215,7 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1246,18 +1246,18 @@ static int mdc_ioc_hsm_current_action(struct obd_export *exp,

rc = mdc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

req_hca = req_capsule_server_get(&req->rq_pill,
&RMF_MDS_HSM_CURRENT_ACTION);
if (req_hca == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*hca = *req_hca;

-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1272,7 +1272,7 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
MDS_HSM_CT_UNREGISTER);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
@@ -1280,7 +1280,7 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1311,17 +1311,17 @@ static int mdc_ioc_hsm_state_get(struct obd_export *exp,

rc = mdc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
if (req_hus == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*hus = *req_hus;

-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1352,14 +1352,14 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,
req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
if (req_hss == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}
*req_hss = *hss;

ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1377,7 +1377,7 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
@@ -1398,7 +1398,7 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
if (req_hr == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}
*req_hr = hur->hur_request;

@@ -1406,7 +1406,7 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
if (req_hui == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}
memcpy(req_hui, hur->hur_user_item,
hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
@@ -1415,14 +1415,14 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
if (req_opaque == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}
memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);

ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index d6c1447..3a56fb7 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -291,12 +291,12 @@ static int osc_getattr(const struct lu_env *env, struct obd_export *exp,

rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
if (body == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
@@ -306,7 +306,7 @@ static int osc_getattr(const struct lu_env *env, struct obd_export *exp,
oinfo->oi_oa->o_blksize = cli_brw_size(exp->exp_obd);
oinfo->oi_oa->o_valid |= OBD_MD_FLBLKSZ;

- out:
+ finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -336,18 +336,18 @@ static int osc_setattr(const struct lu_env *env, struct obd_export *exp,

rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
if (body == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

lustre_get_wire_obdo(&req->rq_import->imp_connect_data, oinfo->oi_oa,
&body->oa);

-out:
+finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -1276,7 +1276,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,

if (desc == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}
/* NB request now owns desc and will free it when it gets freed */

@@ -1407,7 +1407,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
*reqp = req;
return 0;

- out:
+ finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -2513,17 +2513,17 @@ static int osc_statfs(const struct lu_env *env, struct obd_export *exp,

rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
if (msfs == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*osfs = *msfs;

- out:
+ finish_request:
ptlrpc_req_finished(req);
return rc;
}
@@ -2718,16 +2718,16 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp,
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

reply = req_capsule_server_get(&req->rq_pill, &RMF_OBD_ID);
if (reply == NULL) {
rc = -EPROTO;
- goto out;
+ goto finish_request;
}

*((u64 *)val) = *reply;
- out:
+ finish_request:
ptlrpc_req_finished(req);
return rc;
} else if (KEY_IS(KEY_FIEMAP)) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
index 5122205..150d2ec 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
@@ -176,26 +176,26 @@ static int llog_client_next_block(const struct lu_env *env,
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
if (body == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

/* The log records are swabbed as they are processed */
ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
if (ptr == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

*cur_idx = body->lgd_saved_index;
*cur_offset = body->lgd_cur_offset;

memcpy(buf, ptr, len);
-out:
+finish_request:
ptlrpc_req_finished(req);
err_exit:
LLOG_CLIENT_EXIT(loghandle->lgh_ctxt, imp);
@@ -233,22 +233,22 @@ static int llog_client_prev_block(const struct lu_env *env,

rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
if (body == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
if (ptr == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

memcpy(buf, ptr, len);
-out:
+finish_request:
ptlrpc_req_finished(req);
err_exit:
LLOG_CLIENT_EXIT(loghandle->lgh_ctxt, imp);
@@ -282,12 +282,12 @@ static int llog_client_read_header(const struct lu_env *env,
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
if (hdr == NULL) {
rc = -EFAULT;
- goto out;
+ goto finish_request;
}

memcpy(handle->lgh_hdr, hdr, sizeof(*hdr));
@@ -305,7 +305,7 @@ static int llog_client_read_header(const struct lu_env *env,
CERROR("you may need to re-run lconf --write_conf.\n");
rc = -EIO;
}
-out:
+finish_request:
ptlrpc_req_finished(req);
err_exit:
LLOG_CLIENT_EXIT(handle->lgh_ctxt, imp);
--
2.6.3

2015-12-13 13:56:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/7] staging: lustre: Rename a jump label for a kfree(key) call

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 10:56:35 +0100

This issue was detected by using the Coccinelle software.

Choose a jump label according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mdc/mdc_request.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 2a76685..2085ba6 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1125,7 +1125,7 @@ static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)

if (!fid_is_sane(&gf->gf_fid)) {
rc = -EINVAL;
- goto out;
+ goto free_key;
}

/* Val is struct getinfo_fid2path result plus path */
@@ -1133,20 +1133,19 @@ static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)

rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
if (rc != 0 && rc != -EREMOTE)
- goto out;
+ goto free_key;

if (vallen <= sizeof(*gf)) {
rc = -EPROTO;
- goto out;
+ goto free_key;
} else if (vallen > sizeof(*gf) + gf->gf_pathlen) {
rc = -EOVERFLOW;
- goto out;
+ goto free_key;
}

CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n%s\n",
PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
-
-out:
+free_key:
kfree(key);
return rc;
}
--
2.6.3

2015-12-13 13:56:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/7] staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:00:32 +0100

The variable "mne_swab" will eventually be set to an appropriate value
from a call of the ptlrpc_rep_need_swab() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index 2c48847..da130f4 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1293,7 +1293,7 @@ static int mgc_process_recover_log(struct obd_device *obd,
struct page **pages;
int nrpages;
bool eof = true;
- bool mne_swab = false;
+ bool mne_swab;
int i;
int ealen;
int rc;
--
2.6.3

2015-12-13 13:57:45

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:21:17 +0100

A few checks would be performed by the mgc_process_recover_log() function
even if it is known already that the passed variable "pages" contained
a null pointer.

* Let us return directly if a call of the kcalloc() function failed.

* Move assignments for the variables "eof" and "req" behind
this memory allocation.

* Delete a sanity check then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index da130f4..f3b4c30 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1285,14 +1285,14 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
static int mgc_process_recover_log(struct obd_device *obd,
struct config_llog_data *cld)
{
- struct ptlrpc_request *req = NULL;
+ struct ptlrpc_request *req;
struct config_llog_instance *cfg = &cld->cld_cfg;
struct mgs_config_body *body;
struct mgs_config_res *res;
struct ptlrpc_bulk_desc *desc;
struct page **pages;
int nrpages;
- bool eof = true;
+ bool eof;
bool mne_swab;
int i;
int ealen;
@@ -1309,10 +1309,11 @@ static int mgc_process_recover_log(struct obd_device *obd,
nrpages = CONFIG_READ_NRPAGES_INIT;

pages = kcalloc(nrpages, sizeof(*pages), GFP_KERNEL);
- if (pages == NULL) {
- rc = -ENOMEM;
- goto out;
- }
+ if (!pages)
+ return -ENOMEM;
+
+ req = NULL;
+ eof = true;

for (i = 0; i < nrpages; i++) {
pages[i] = alloc_page(GFP_KERNEL);
@@ -1432,14 +1433,12 @@ out:
if (rc == 0 && !eof)
goto again;

- if (pages) {
- for (i = 0; i < nrpages; i++) {
- if (pages[i] == NULL)
- break;
- __free_page(pages[i]);
- }
- kfree(pages);
+ for (i = 0; i < nrpages; i++) {
+ if (pages[i] == NULL)
+ break;
+ __free_page(pages[i]);
}
+ kfree(pages);
return rc;
}

--
2.6.3

2015-12-13 13:58:54

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/7] staging: lustre: A few checks less in mgc_process_recover_log() after error detection

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 13:03:58 +0100

A few checks would be performed by the mgc_process_recover_log() function
even if it was determined that a call of the alloc_page() function failed.

* This implementation detail could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Move the assignment for the variable "eof" behind the memory allocation.

* Delete another sanity check then.

* The variable "req" will eventually be set to an appropriate pointer
from a call of the ptlrpc_request_alloc() function.
Thus let us omit the explicit initialisation before.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 32 +++++++++++--------------
1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index f3b4c30..7048722 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1312,17 +1312,15 @@ static int mgc_process_recover_log(struct obd_device *obd,
if (!pages)
return -ENOMEM;

- req = NULL;
- eof = true;
-
for (i = 0; i < nrpages; i++) {
pages[i] = alloc_page(GFP_KERNEL);
if (pages[i] == NULL) {
rc = -ENOMEM;
- goto out;
+ goto free_pages;
}
}

+ eof = true;
again:
LASSERT(cld_is_recover(cld));
LASSERT(mutex_is_locked(&cld->cld_lock));
@@ -1330,12 +1328,12 @@ again:
&RQF_MGS_CONFIG_READ);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto free_pages;
}

rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
if (rc)
- goto out;
+ goto finish_request;

/* pack request */
body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
@@ -1344,7 +1342,7 @@ again:
if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name))
>= sizeof(body->mcb_name)) {
rc = -E2BIG;
- goto out;
+ goto finish_request;
}
body->mcb_offset = cfg->cfg_last_idx + 1;
body->mcb_type = cld->cld_type;
@@ -1356,7 +1354,7 @@ again:
MGS_BULK_PORTAL);
if (desc == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

for (i = 0; i < nrpages; i++)
@@ -1365,12 +1363,12 @@ again:
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
if (res->mcr_size < res->mcr_offset) {
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

/* always update the index even though it might have errors with
@@ -1384,18 +1382,18 @@ again:
ealen = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, 0);
if (ealen < 0) {
rc = ealen;
- goto out;
+ goto finish_request;
}

if (ealen > nrpages << PAGE_CACHE_SHIFT) {
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

if (ealen == 0) { /* no logs transferred */
if (!eof)
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

mne_swab = !!ptlrpc_rep_need_swab(req);
@@ -1425,14 +1423,12 @@ again:

ealen -= PAGE_CACHE_SIZE;
}
-
-out:
- if (req)
- ptlrpc_req_finished(req);
+finish_request:
+ ptlrpc_req_finished(req);

if (rc == 0 && !eof)
goto again;
-
+free_pages:
for (i = 0; i < nrpages; i++) {
if (pages[i] == NULL)
break;
--
2.6.3

2015-12-13 14:00:27

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 7/7] staging: lustre: Rename a jump label for module_put() calls

From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 14:05:57 +0100

This issue was detected by using the Coccinelle software.

Choose a jump label according to the current Linux coding style convention.
I suggest to improve this implementation detail by the reuse of a script
like the following for the semantic patch language.

@rename_jump_label exists@
identifier target != put_module, work;
type return_type;
@@
return_type work(...)
{
... when any
goto
-target
+put_module
;
... when any
-target
+put_module
:
module_put(...);
... when any
}

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/llite/lloop.c | 8 ++--
drivers/staging/lustre/lustre/mdc/mdc_request.c | 52 ++++++++++++-------------
drivers/staging/lustre/lustre/osc/osc_request.c | 24 ++++++------
3 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/lloop.c b/drivers/staging/lustre/lustre/llite/lloop.c
index 420d391..ebeef3b 100644
--- a/drivers/staging/lustre/lustre/llite/lloop.c
+++ b/drivers/staging/lustre/lustre/llite/lloop.c
@@ -484,14 +484,14 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,

error = -EBUSY;
if (lo->lo_state != LLOOP_UNBOUND)
- goto out;
+ goto put_module;

mapping = file->f_mapping;
inode = mapping->host;

error = -EINVAL;
if (!S_ISREG(inode->i_mode) || inode->i_sb->s_magic != LL_SUPER_MAGIC)
- goto out;
+ goto put_module;

if (!(file->f_mode & FMODE_WRITE))
lo_flags |= LO_FLAGS_READ_ONLY;
@@ -500,7 +500,7 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,

if ((loff_t)(sector_t)size != size) {
error = -EFBIG;
- goto out;
+ goto put_module;
}

/* remove all pages in cache so as dirty pages not to be existent. */
@@ -542,7 +542,7 @@ static int loop_set_fd(struct lloop_device *lo, struct file *unused,
down(&lo->lo_sem);
return 0;

-out:
+put_module:
/* This is safe: open() is still holding a reference. */
module_put(THIS_MODULE);
return error;
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 2085ba6..eaeca9a 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1734,7 +1734,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
switch (cmd) {
case OBD_IOC_CHANGELOG_SEND:
rc = mdc_ioc_changelog_send(obd, karg);
- goto out;
+ goto put_module;
case OBD_IOC_CHANGELOG_CLEAR: {
struct ioc_changelog *icc = karg;
struct changelog_setinfo cs = {
@@ -1745,47 +1745,47 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
NULL);
- goto out;
+ goto put_module;
}
case OBD_IOC_FID2PATH:
rc = mdc_ioc_fid2path(exp, karg);
- goto out;
+ goto put_module;
case LL_IOC_HSM_CT_START:
rc = mdc_ioc_hsm_ct_start(exp, karg);
/* ignore if it was already registered on this MDS. */
if (rc == -EEXIST)
rc = 0;
- goto out;
+ goto put_module;
case LL_IOC_HSM_PROGRESS:
rc = mdc_ioc_hsm_progress(exp, karg);
- goto out;
+ goto put_module;
case LL_IOC_HSM_STATE_GET:
rc = mdc_ioc_hsm_state_get(exp, karg);
- goto out;
+ goto put_module;
case LL_IOC_HSM_STATE_SET:
rc = mdc_ioc_hsm_state_set(exp, karg);
- goto out;
+ goto put_module;
case LL_IOC_HSM_ACTION:
rc = mdc_ioc_hsm_current_action(exp, karg);
- goto out;
+ goto put_module;
case LL_IOC_HSM_REQUEST:
rc = mdc_ioc_hsm_request(exp, karg);
- goto out;
+ goto put_module;
case OBD_IOC_CLIENT_RECOVER:
rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
if (rc < 0)
- goto out;
+ goto put_module;
rc = 0;
- goto out;
+ goto put_module;
case IOC_OSC_SET_ACTIVE:
rc = ptlrpc_set_import_active(imp, data->ioc_offset);
- goto out;
+ goto put_module;
case OBD_IOC_POLL_QUOTACHECK:
rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
- goto out;
+ goto put_module;
case OBD_IOC_PING_TARGET:
rc = ptlrpc_obd_ping(obd);
- goto out;
+ goto put_module;
/*
* Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
* LMV instead of MDC. But when the cluster is upgraded from 1.8,
@@ -1798,7 +1798,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,

if (*((__u32 *) data->ioc_inlbuf2) != 0) {
rc = -ENODEV;
- goto out;
+ goto put_module;
}

/* copy UUID */
@@ -1806,24 +1806,24 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
min_t(size_t, data->ioc_plen2,
sizeof(struct obd_uuid)))) {
rc = -EFAULT;
- goto out;
+ goto put_module;
}

rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
0);
if (rc != 0)
- goto out;
+ goto put_module;

if (copy_to_user(data->ioc_pbuf1, &stat_buf,
min_t(size_t, data->ioc_plen1,
sizeof(stat_buf)))) {
rc = -EFAULT;
- goto out;
+ goto put_module;
}

rc = 0;
- goto out;
+ goto put_module;
}
case OBD_IOC_QUOTACTL: {
struct if_quotactl *qctl = karg;
@@ -1832,7 +1832,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
if (!oqctl) {
rc = -ENOMEM;
- goto out;
+ goto put_module;
}

QCTL_COPY(oqctl, qctl);
@@ -1844,26 +1844,26 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
}

kfree(oqctl);
- goto out;
+ goto put_module;
}
case LL_IOC_GET_CONNECT_FLAGS:
if (copy_to_user(uarg, exp_connect_flags_ptr(exp),
sizeof(*exp_connect_flags_ptr(exp)))) {
rc = -EFAULT;
- goto out;
+ goto put_module;
}

rc = 0;
- goto out;
+ goto put_module;
case LL_IOC_LOV_SWAP_LAYOUTS:
rc = mdc_ioc_swap_layouts(exp, karg);
- goto out;
+ goto put_module;
default:
CERROR("unrecognised ioctl: cmd = %#x\n", cmd);
rc = -ENOTTY;
- goto out;
+ goto put_module;
}
-out:
+put_module:
module_put(THIS_MODULE);

return rc;
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 3a56fb7..3ee1ff8 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -2611,7 +2611,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
len = 0;
if (obd_ioctl_getdata(&buf, &len, uarg)) {
err = -EINVAL;
- goto out;
+ goto put_module;
}

data = (struct obd_ioctl_data *)buf;
@@ -2619,13 +2619,13 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
if (sizeof(*desc) > data->ioc_inllen1) {
obd_ioctl_freedata(buf, len);
err = -EINVAL;
- goto out;
+ goto put_module;
}

if (data->ioc_inllen2 < sizeof(uuid)) {
obd_ioctl_freedata(buf, len);
err = -EINVAL;
- goto out;
+ goto put_module;
}

desc = (struct lov_desc *)data->ioc_inlbuf1;
@@ -2643,39 +2643,39 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
if (err)
err = -EFAULT;
obd_ioctl_freedata(buf, len);
- goto out;
+ goto put_module;
}
case LL_IOC_LOV_SETSTRIPE:
err = obd_alloc_memmd(exp, karg);
if (err > 0)
err = 0;
- goto out;
+ goto put_module;
case LL_IOC_LOV_GETSTRIPE:
err = osc_getstripe(karg, uarg);
- goto out;
+ goto put_module;
case OBD_IOC_CLIENT_RECOVER:
err = ptlrpc_recover_import(obd->u.cli.cl_import,
data->ioc_inlbuf1, 0);
if (err > 0)
err = 0;
- goto out;
+ goto put_module;
case IOC_OSC_SET_ACTIVE:
err = ptlrpc_set_import_active(obd->u.cli.cl_import,
data->ioc_offset);
- goto out;
+ goto put_module;
case OBD_IOC_POLL_QUOTACHECK:
err = osc_quota_poll_check(exp, karg);
- goto out;
+ goto put_module;
case OBD_IOC_PING_TARGET:
err = ptlrpc_obd_ping(obd);
- goto out;
+ goto put_module;
default:
CDEBUG(D_INODE, "unrecognised ioctl %#x by %s\n",
cmd, current_comm());
err = -ENOTTY;
- goto out;
+ goto put_module;
}
-out:
+put_module:
module_put(THIS_MODULE);
return err;
}
--
2.6.3

2015-12-14 00:26:00

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

On (12/11/15 19:24), SF Markus Elfring wrote:
[..]
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 47915d7..69d7fcd 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> size_t clen;
> unsigned long handle;
> struct page *page;
> - unsigned char *user_mem, *cmem, *src, *uncmem = NULL;
> + unsigned char *user_mem, *cmem, *src, *uncmem;
> struct zram_meta *meta = zram->meta;
> - struct zcomp_strm *zstrm = NULL;
> + struct zcomp_strm *zstrm;
> unsigned long alloced_pages;
>
> page = bvec->bv_page;
> @@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> * before to write the changes.
> */
> uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
> - if (!uncmem) {
> - ret = -ENOMEM;
> - goto out;
> - }
> + if (!uncmem)
> + return -ENOMEM;

ok.

> ret = zram_decompress_page(zram, uncmem, index);
> if (ret)
> - goto out;
> + goto free_uncmem;

here and later, I don't want to split `out' label.
you still need to do both 'if zstrm' and 'if is_partial_io' checks anyway, what's the gain?
the more labels we have the trickier it may get.

> }
>
> zstrm = zcomp_strm_find(zram->comp);
> @@ -696,7 +694,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
>
> atomic64_inc(&zram->stats.zero_pages);
> ret = 0;
> - goto out;
> + goto check_strm;
> }
>
> ret = zcomp_compress(zram->comp, zstrm, uncmem, &clen);
> @@ -708,7 +706,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
>
> if (unlikely(ret)) {
> pr_err("Compression failed! err=%d\n", ret);
> - goto out;
> + goto check_strm;
> }
> src = zstrm->buffer;
> if (unlikely(clen > max_zpage_size)) {
> @@ -722,7 +720,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> pr_err("Error allocating memory for compressed page: %u, size=%zu\n",
> index, clen);
> ret = -ENOMEM;
> - goto out;
> + goto check_strm;
> }
>
> alloced_pages = zs_get_total_pages(meta->mem_pool);
> @@ -731,7 +729,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> if (zram->limit_pages && alloced_pages > zram->limit_pages) {
> zs_free(meta->mem_pool, handle);
> ret = -ENOMEM;
> - goto out;
> + goto check_strm;
> }
>
> cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO);
> @@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
> /* Update stats */
> atomic64_add(clen, &zram->stats.compr_data_size);
> atomic64_inc(&zram->stats.pages_stored);
> -out:
> +check_strm:
> if (zstrm)
> zcomp_strm_release(zram->comp, zstrm);
> - if (is_partial_io(bvec))
> + if (is_partial_io(bvec)) {
> +free_uncmem:
> kfree(uncmem);
> + }

a label inside of `if'? no.
keep it the way it is please.

> return ret;
> }

-ss

2015-12-14 00:35:20

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()

Cc Jens, Andrew, Geert

On (12/11/15 19:26), SF Markus Elfring wrote:
>
> This issue was detected by using the Coccinelle software.
>
> * Let us return directly if a call of the function "register_blkdev" failed.
>
> * Remove the jump label "err" then.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/block/z2ram.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
> index 968f9e5..b07581d 100644
> --- a/drivers/block/z2ram.c
> +++ b/drivers/block/z2ram.c
> @@ -345,9 +345,8 @@ z2_init(void)
> if (!MACH_IS_AMIGA)
> return -ENODEV;
>
> - ret = -EBUSY;
> if (register_blkdev(Z2RAM_MAJOR, DEVICE_NAME))
> - goto err;
> + return -EBUSY;
>
> ret = -ENOMEM;
> z2ram_gendisk = alloc_disk(1);
> @@ -374,7 +373,6 @@ out_queue:
> put_disk(z2ram_gendisk);
> out_disk:
> unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
> -err:
> return ret;
> }

z2ram and zram are different drivers, but the change looks
ok to me.

z2ram can be improved in many ways, so my question is - do
people still use it?

-ss

2015-12-14 06:53:46

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls

Markus, please stop sending these things to rename out labels unless
there is a bug. CodingStyle allows out labels.

regards,
dan carpenter

2015-12-14 06:58:51

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

>> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
>> index 47915d7..69d7fcd 100644
>> --- a/drivers/block/zram/zram_drv.c
>> +++ b/drivers/block/zram/zram_drv.c
>> @@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
>> size_t clen;
>> unsigned long handle;
>> struct page *page;
>> - unsigned char *user_mem, *cmem, *src, *uncmem = NULL;
>> + unsigned char *user_mem, *cmem, *src, *uncmem;
>> struct zram_meta *meta = zram->meta;
>> - struct zcomp_strm *zstrm = NULL;
>> + struct zcomp_strm *zstrm;
>> unsigned long alloced_pages;
>>
>> page = bvec->bv_page;
>> @@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
>> * before to write the changes.
>> */
>> uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
>> - if (!uncmem) {
>> - ret = -ENOMEM;
>> - goto out;
>> - }
>> + if (!uncmem)
>> + return -ENOMEM;
>
> ok.

Thanks for your terse acknowledgement.


>> ret = zram_decompress_page(zram, uncmem, index);
>> if (ret)
>> - goto out;
>> + goto free_uncmem;
>
> here and later, I don't want to split `out' label.

I guess that corresponding software design concerns can evolve a bit.


> you still need to do both 'if zstrm' and 'if is_partial_io' checks anyway, what's the gain?

How are the chances to reduce the number of dispensable sanity checks?


> the more labels we have the trickier it may get.

I hope that more unique jump labels can make the involved exception handling also clearer.


>> @@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
>> /* Update stats */
>> atomic64_add(clen, &zram->stats.compr_data_size);
>> atomic64_inc(&zram->stats.pages_stored);
>> -out:
>> +check_strm:
>> if (zstrm)
>> zcomp_strm_release(zram->comp, zstrm);
>> - if (is_partial_io(bvec))
>> + if (is_partial_io(bvec)) {
>> +free_uncmem:
>> kfree(uncmem);
>> + }
>
> a label inside of `if'? no.

Do any more software developers find such an use case interesting?


> keep it the way it is please.

I suggest to make the affected exception handling a bit more efficient.
Such source code fine-tuning has got a few special consequences.

Regards,
Markus

2015-12-14 07:17:39

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

> I suggest to make the affected exception handling a bit more efficient.
> Such source code fine-tuning has got a few special consequences.

Exception handling is by definition exceptional, and thus its efficiency
is rarely important. What is important is that it should be correct, and
ideally clearly correct, so that someone can check its correctness easily.
Optimizations, if they have any effect at all, typically make the
correctness less obvious.

julia

2015-12-14 08:41:24

by Johannes Thumshirn

[permalink] [raw]
Subject: Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly

On Sat, Dec 12, 2015 at 10:49:40PM +0300, Dan Carpenter wrote:
> On Sat, Dec 12, 2015 at 03:34:50PM +0100, SF Markus Elfring wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Sat, 12 Dec 2015 11:36:02 +0100
> >
> > Omit the unnecessary setting to a null pointer for the variable "param"
> > at the beginning of the function "iscsi_set_default_param"
> > because it can be directly initialized with the return value
> > from the function "kzalloc".
> >
> > Signed-off-by: Markus Elfring <[email protected]>
> > ---
> > drivers/target/iscsi/iscsi_target_parameters.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
> > index 3a1f9a7..0a8bd3f 100644
> > --- a/drivers/target/iscsi/iscsi_target_parameters.c
> > +++ b/drivers/target/iscsi/iscsi_target_parameters.c
> > @@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
> > char *name, char *value, u8 phase, u8 scope, u8 sender,
> > u16 type_range, u8 use)
> > {
> > - struct iscsi_param *param = NULL;
> > + struct iscsi_param *param = kzalloc(sizeof(*param), GFP_KERNEL);
> >
> > - param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
> > if (!param) {
> > pr_err("Unable to allocate memory for parameter.\n");
> > goto out;
>
> It's better to just get rid of the initialization but leave the
> kzalloc() as-is for two reasons.
>
> 1) Initializer code normally contains more bugs per line than other
> code. I am thinking about dereferencing pointers before checking
> for NULL or not checking the allocation for failure.
>
> 2) It puts a blank line between the allocation and the check for
> failure. It's like a new paragraph. The allocation and the check
> should be next to each other.

I agree with Dan here. Please don't do it.

@@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
char *name, char *value, u8 phase, u8 scope, u8 sender,
u16 type_range, u8 use)
{
- struct iscsi_param *param = NULL;
+ struct iscsi_param *param;

param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
if (!param) {
pr_err("Unable to allocate memory for parameter.\n");


This way it would be _far_ more readable. IMHO one should have a 1 action per
line of code style and only assign values in at declaration time if really
necessary.

But what is the benefit from this? Is it fixing a (hypothetical) bug? I somehow
fail to see it.

Thanks,
Johannes

--
Johannes Thumshirn Storage
[email protected] +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

2015-12-14 09:08:23

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls

> Markus, please stop sending these things to rename out labels unless
> there is a bug. CodingStyle allows out labels.

How does this feedback fit to information like the following?

"…
Chapter 7: …

Choose label names which say what the goto does or why the goto exists.
… Avoid using GW-BASIC names …
…"

Regards,
Markus

2015-12-14 09:11:03

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()

On Mon, Dec 14, 2015 at 1:36 AM, Sergey Senozhatsky
<[email protected]> wrote:
> Cc Jens, Andrew, Geert
>
> On (12/11/15 19:26), SF Markus Elfring wrote:
>>
>> This issue was detected by using the Coccinelle software.
>>
>> * Let us return directly if a call of the function "register_blkdev" failed.
>>
>> * Remove the jump label "err" then.
>>
>> Signed-off-by: Markus Elfring <[email protected]>

Acked-by: Geert Uytterhoeven <[email protected]>

>> ---
>> drivers/block/z2ram.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
>> index 968f9e5..b07581d 100644
>> --- a/drivers/block/z2ram.c
>> +++ b/drivers/block/z2ram.c
>> @@ -345,9 +345,8 @@ z2_init(void)
>> if (!MACH_IS_AMIGA)
>> return -ENODEV;
>>
>> - ret = -EBUSY;
>> if (register_blkdev(Z2RAM_MAJOR, DEVICE_NAME))
>> - goto err;
>> + return -EBUSY;
>>
>> ret = -ENOMEM;
>> z2ram_gendisk = alloc_disk(1);
>> @@ -374,7 +373,6 @@ out_queue:
>> put_disk(z2ram_gendisk);
>> out_disk:
>> unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
>> -err:
>> return ret;
>> }
>
> z2ram and zram are different drivers, but the change looks
> ok to me.
>
> z2ram can be improved in many ways, so my question is - do
> people still use it?

I think it's still used.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2015-12-14 09:31:54

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls

On Mon, Dec 14, 2015 at 10:08:03AM +0100, SF Markus Elfring wrote:
> > Markus, please stop sending these things to rename out labels unless
> > there is a bug. CodingStyle allows out labels.
>
> How does this feedback fit to information like the following?
>
> "…
> Chapter 7: …
> …
> Choose label names which say what the goto does or why the goto exists.

A lot of people think "out" says what the goto does and why it exists.
I personally don't agree with them but if you look at when I complain
about it, it's almost always when it causes a bug.

> … Avoid using GW-BASIC names …

Those when people just use numbers for their label names instead of
words like out1, out2, out4, out5. It's a different thing.

regards,
dan carpenter

2015-12-14 10:02:24

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

On (12/14/15 07:58), SF Markus Elfring wrote:
[..]
> > keep it the way it is please.
>
> I suggest to make the affected exception handling a bit more efficient.
> Such source code fine-tuning has got a few special consequences.

by 'more efficient' you mean saving cpu cycles on 'bvec->bv_len != PAGE_SIZE'
comparison in exception/error path?

...
check_strm:
if (zstrm)
zcomp_strm_release(zram->comp, zstrm);
if (is_partial_io(bvec)) {
free_uncmem:
kfree(uncmem);
}
...


no.

-ss

2015-12-14 10:03:44

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Rename a jump label for ptlrpc_req_finished() calls

>>> Markus, please stop sending these things to rename out labels unless
>>> there is a bug. CodingStyle allows out labels.
>>
>> How does this feedback fit to information like the following?
>>
>> "…
>> Chapter 7: …
>> …
>> Choose label names which say what the goto does or why the goto exists.
>
> A lot of people think "out" says what the goto does and why it exists.

I have got the impression that this short identifier is only partly appropriate.


> I personally don't agree with them

I guess that my opinion goes into a similar direction here.


> but if you look at when I complain about it, it's almost always
> when it causes a bug.

I agree that the combination with bug fixing is more appealing
than an attempt to improve coding style applications.


>> … Avoid using GW-BASIC names …
>
> Those when people just use numbers for their label names instead of
> words like out1, out2, out4, out5. It's a different thing.

The difference is not so clear for me as it appears to you.
How many software developers can still remember habits around
the selection of such identifiers from GW-BASIC times?

Regards,
Markus

2015-12-14 11:00:20

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Sun, Dec 13, 2015 at 02:57:38PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 13 Dec 2015 12:21:17 +0100
>
> A few checks would be performed by the mgc_process_recover_log() function
> even if it is known already that the passed variable "pages" contained
> a null pointer.
>
> * Let us return directly if a call of the kcalloc() function failed.
>
> * Move assignments for the variables "eof" and "req" behind
> this memory allocation.

Why? Then in the next patch it moves again. It's like cup shuffle to
read these patches sometimes.

regards,
dan carpenter

2015-12-14 11:38:42

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly

> @@ -127,9 +127,8 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
> char *name, char *value, u8 phase, u8 scope, u8 sender,
> u16 type_range, u8 use)
> {
> - struct iscsi_param *param = NULL;
> + struct iscsi_param *param;
>
> param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
> if (!param) {
> pr_err("Unable to allocate memory for parameter.\n");
>
>
> This way it would be _far_ more readable.

I guess that there are some opinions available for this implementation detail.


> IMHO one should have a 1 action per line of code style

How often do you care for such style issues?


> and only assign values in at declaration time if really necessary.

Which is or might become the official Linux coding style recommendation
for this aspect?


> But what is the benefit from this? Is it fixing a (hypothetical) bug?

I find the shown null pointer initialisation just needless.

Regards,
Markus

2015-12-14 12:04:34

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection

>> A few checks would be performed by the mgc_process_recover_log() function
>> even if it is known already that the passed variable "pages" contained
>> a null pointer.
>>
>> * Let us return directly if a call of the kcalloc() function failed.
>>
>> * Move assignments for the variables "eof" and "req" behind
>> this memory allocation.
>
> Why?

The positions of their initialisation depends on the selected exception
handling implementation, doesn't it?

Can you accept the proposed changes around the affected memory allocations?


> Then in the next patch it moves again.

This detail is a matter of patch granularity.


> It's like cup shuffle to read these patches sometimes.

Do you prefer to stash any changes together for a bigger update step?

Regards,
Markus

2015-12-14 12:39:12

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Mon, Dec 14, 2015 at 01:04:14PM +0100, SF Markus Elfring wrote:
> >> A few checks would be performed by the mgc_process_recover_log() function
> >> even if it is known already that the passed variable "pages" contained
> >> a null pointer.
> >>
> >> * Let us return directly if a call of the kcalloc() function failed.
> >>
> >> * Move assignments for the variables "eof" and "req" behind
> >> this memory allocation.
> >
> > Why?
>
> The positions of their initialisation depends on the selected exception
> handling implementation, doesn't it?
>
> Can you accept the proposed changes around the affected memory allocations?
>

Just leave it as-is if there is no reason.

>
> > Then in the next patch it moves again.
>
> This detail is a matter of patch granularity.
>
>
> > It's like cup shuffle to read these patches sometimes.
>
> Do you prefer to stash any changes together for a bigger update step?

Yes. Patches 5 and 6 would be easier to review if they were folded into
one patch.

regards,
dan carpenter

2015-12-14 12:45:29

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection

>> Can you accept the proposed changes around the affected memory allocations?
>
> Just leave it as-is if there is no reason.

I suggest to make the implementation of the function "mgc_process_recover_log"
a bit more efficient.


>> Do you prefer to stash any changes together for a bigger update step?
>
> Yes. Patches 5 and 6 would be easier to review if they were folded into
> one patch.

I do not like patch squashing for my update suggestions here.

Regards,
Markus

2015-12-14 13:58:37

by Dan Carpenter

[permalink] [raw]
Subject: Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Mon, Dec 14, 2015 at 01:45:11PM +0100, SF Markus Elfring wrote:
> >> Do you prefer to stash any changes together for a bigger update step?
> >
> > Yes. Patches 5 and 6 would be easier to review if they were folded into
> > one patch.
>
> I do not like patch squashing for my update suggestions here.

I am a maintainer in drivers/staging. I am telling you what you need to
do if you want us to apply your patch. What you do with that
information is up to you.

regards,
dan carpenter

2015-12-14 14:04:05

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection

>> I suggest to make the affected exception handling a bit more efficient.
>> Such source code fine-tuning has got a few special consequences.
>
> by 'more efficient' you mean saving cpu cycles on 'bvec->bv_len != PAGE_SIZE'
> comparison in exception/error path?

Yes …


> ...
> check_strm:
> if (zstrm)
> zcomp_strm_release(zram->comp, zstrm);
> if (is_partial_io(bvec)) {
> free_uncmem:
> kfree(uncmem);
> }
> ...

I propose to jump over two sanity checks.


> no.

Thanks for your feedback.

Regards,
Markus

2015-12-14 17:43:33

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection

>> I do not like patch squashing for my update suggestions here.
>
> I am a maintainer in drivers/staging.

Thanks for this information.


> I am telling you what you need to do if you want us to apply your patch.

I am still waiting for a bit more constructive feedback for this
patch series. How many days should I wait before I should send adjusted
update suggestions for this approach?


> What you do with that information is up to you.

Our software development dialogue seems to trigger special
challenges between us so far.
Are you generally willing to change the exception handling for
the memory allocations in the function "mgc_process_recover_log"
at all?

Regards,
Markus

2015-12-14 22:10:41

by SF Markus Elfring

[permalink] [raw]
Subject: [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection

From: Markus Elfring <[email protected]>
Date: Mon, 14 Dec 2015 23:01:32 +0100

A status check was performed by the fsl_get_immr() function even if it
was known already that a system setting did not fit to the expectations.

This implementation detail could be improved by an adjustment for
a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
arch/powerpc/boot/fsl-soc.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/boot/fsl-soc.c b/arch/powerpc/boot/fsl-soc.c
index b835ed6..ff1dae3 100644
--- a/arch/powerpc/boot/fsl-soc.c
+++ b/arch/powerpc/boot/fsl-soc.c
@@ -34,24 +34,24 @@ u32 *fsl_get_immr(void)
naddr = 2;

if (naddr != 1 && naddr != 2)
- goto err;
+ goto report_failure;

size = getprop(soc, "ranges", prop_buf, MAX_PROP_LEN);

if (size < 12)
- goto err;
+ goto report_failure;
if (prop_buf[0] != 0)
- goto err;
+ goto report_failure;
if (naddr == 2 && prop_buf[1] != 0)
- goto err;
+ goto report_failure;

if (!dt_xlate_addr(soc, prop_buf + naddr, 8, &ret))
ret = 0;
}

-err:
- if (!ret)
+ if (!ret) {
+report_failure:
printf("fsl_get_immr: Failed to find immr base\r\n");
-
+ }
return (u32 *)ret;
}
--
2.6.3

2015-12-14 22:34:34

by Scott Wood

[permalink] [raw]
Subject: Re: [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection

On Mon, 2015-12-14 at 23:10 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 14 Dec 2015 23:01:32 +0100
>
> A status check was performed by the fsl_get_immr() function even if it
> was known already that a system setting did not fit to the expectations.
>
> This implementation detail could be improved by an adjustment for
> a jump label according to the Linux coding style convention.

What is the actual problem you're trying to solve? Cluttering the code to
micro-optimize an error path is not an improvement.

-Scott

2015-12-15 11:43:14

by Dan Carpenter

[permalink] [raw]
Subject: Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Mon, Dec 14, 2015 at 06:43:15PM +0100, SF Markus Elfring wrote:
> Our software development dialogue seems to trigger special
> challenges between us so far.

I try very hard to review patches mechanically and not be biased so that
after a while people know if their patches will be merged or not without
waiting for feedback.

In this case, I had asked you not to send patches renaming out labels
and then the next day you sent me a string of patches renaming out
labels. If you were a lustre dev then I would accept these renames
definitely. But I believe that for anyone else, I would ask them what
the point of doing these renames is. I do not think I have been unfair
to you. There was no element of surprise.

Part of the reason we have CodingStyle is so that we can tell people
"That's not in CodingStyle, that's just your own opinion so don't redo
code just because you have a different opinion from the maintainer."

> Are you generally willing to change the exception handling for
> the memory allocations in the function "mgc_process_recover_log"
> at all?

I like the first patch in this series. I do not like the renames. I
don't care too much about patches 5 and 6 except that they should be
folded together and you should not move "req" and "eof" around.

Mostly I wish you would just focus on fixing bugs instead of these sorts
of patches. It is a lot of work for me to explain how to redo patches
but it is worth it for bugfixes.

regards,
dan carpenter

2015-12-15 14:28:04

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

On Sun, 2015-12-13 at 14:52 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 13 Dec 2015 09:30:47 +0100
>
> Six goto statements referred to a source code position directly behind them.
> Thus omit such unnecessary jumps.

I suggest you leave a blank line instead
of deleting the goto.

> diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
[]
> @@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
> ? retval = NULL;
> ? else
> ? retval = dentry;
> - goto out;
> ? out:
> ? if (req)
> ? ptlrpc_req_finished(req);

etc.,,

2015-12-15 14:42:00

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

On Tue, Dec 15, 2015 at 06:27:56AM -0800, Joe Perches wrote:
> On Sun, 2015-12-13 at 14:52 +0100, SF Markus Elfring wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Sun, 13 Dec 2015 09:30:47 +0100
> >
> > Six goto statements referred to a source code position directly behind them.
> > Thus omit such unnecessary jumps.
>
> I suggest you leave a blank line instead
> of deleting the goto.
>

What is the point of the little bunny hop?

regards,
dan carpenter

2015-12-15 15:01:05

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection

> If you were a lustre dev then I would accept these renames definitely.

I find this information interesting.
Would any more contributors like to share their opinion?


> I do not think I have been unfair to you.

This view is correct in principle.


> There was no element of surprise.

I am trying to discuss further "special" update suggestions
where the topic focus might evolve to new directions.
I got the impression that you had some difficulties already
with my previous proposals. So I am unsure about the general
change acceptance from you alone.

You pointed out that you are maintainer for this software area.
I was not so aware about this detail while I noticed that
you are very active Linux software developer.
(You are not mentioned in the file "MAINTAINERS" for example.)


> Part of the reason we have CodingStyle is so that we can tell people
> "That's not in CodingStyle, that's just your own opinion so don't redo
> code just because you have a different opinion from the maintainer."

I find this description reasonable.

But I see some challenges to improve the coding style specification.
I would appreciate if some items can become less ambiguous and imprecise.
I assume that a few recommendations from the script "checkpatch.pl"
should also be mentioned there.

>
>> Are you generally willing to change the exception handling for
>> the memory allocations in the function "mgc_process_recover_log"
>> at all?
> I like the first patch in this series.

Thanks for a bit of positive feedback.


> I do not like the renames.

I guess that this design aspect can be clarified a bit more.


> I don't care too much about patches 5 and 6 except that they should be
> folded together and you should not move "req" and "eof" around.

I can understand this concern better than your first response
for these update steps.

I might send an adjusted patch series a few days later.


> Mostly I wish you would just focus on fixing bugs instead of these sorts
> of patches.

How often are deviations from the coding style also just ordinary bugs?

It seems that changes for this area are occasionally not so attractive
in comparison to software improvements for components
which are more popular.

Regards,
Markus

2015-12-15 15:02:40

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

On Tue, 2015-12-15 at 17:41 +0300, Dan Carpenter wrote:
> On Tue, Dec 15, 2015 at 06:27:56AM -0800, Joe Perches wrote:
> > On Sun, 2015-12-13 at 14:52 +0100, SF Markus Elfring wrote:
> > > From: Markus Elfring <[email protected]>
> > > Date: Sun, 13 Dec 2015 09:30:47 +0100
> > >
> > > Six goto statements referred to a source code position directly behind them.
> > > Thus omit such unnecessary jumps.
> >
> > I suggest you leave a blank line instead
> > of deleting the goto.
> >
>
> What is the point of the little bunny hop?
>
> regards,
> dan carpenter
>

-ENOPARSE little bunny hop
(though I could have said "just leave a blank line)

I think that code blocks are more obvious to read.

This is the original code:

result = foo();
if (result)
goto label;

result = bar();
if (result)
goto label;

result = baz();
if (result)
goto label;

label:
go on...

He proposes:

result = foo();
if (result)
goto label;

result = bar();
if (result)
goto label;

result = baz();
label:
go on...


I don't find the test->goto label; label: use offensive,
but if he does, I think keeping a blank line in place of
the test->goto might be better.

result = foo();
if (result)
goto label;

result = bar();
if (result)
goto label;

result = baz();

label:
go on...

2015-12-15 17:49:20

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

On Tue, Dec 15, 2015 at 07:02:31AM -0800, Joe Perches wrote:
> This is the original code:
>
> result = foo();
> if (result)
> goto label;
>
> result = bar();
> if (result)
> goto label;
>
> result = baz();
> if (result)
> goto label;
>
> label:
> go on...
>

No. There is no test. The original code looks like:

result = foo();
if (result)
goto out;
result = baz();
goto out;
out:
go on..

regards,
dan carpenter

2015-12-15 18:03:14

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions

> This is the original code:
Really ??
> result = baz();
> if (result)
> goto label;
>
> label:
> go on...

I do not see such a source code structure
at the six places I propose to clean-up.


> I don't find the test->goto label; label: use offensive,
> but if he does, I think keeping a blank line in place of
> the test->goto might be better.

I find this an interesting view on source code layout.
Are there any more opinions around such implementation details?

Regards,
Markus

2015-12-15 18:10:19

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions

On Tue, 2015-12-15 at 20:48 +0300, Dan Carpenter wrote:
> On Tue, Dec 15, 2015 at 07:02:31AM -0800, Joe Perches wrote:
> > This is the original code:
> >
> > result = foo();
> > if (result)
> > goto label;
> >
> > result = bar();
> > if (result)
> > goto label;
> >
> > result = baz();
> > if (result)
> > goto label;
> >
> > label:
> > go on...
> >
>
> No.??There is no test.??The original code looks like:
>
> result = foo();
> if (result)
> goto out;
> result = baz();
> goto out;
> out:
> go on..
>
> regards,
> dan carpenter

Here is the original code:
---------------------
/* Copy hsm_progress struct */
req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
if (req_hpk == NULL) {
rc = -EPROTO;
goto out;
}

*req_hpk = *hpk;
req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval);

ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
goto out;
out:
ptlrpc_req_finished(req);
return rc;
}
---------------------

I think if the last goto out; is to be removed,
then it should be replaced by a blank line.

It separates the last operation block from the return.

cheers, Joe

2015-12-15 18:22:16

by Joe Perches

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions

On Tue, 2015-12-15 at 19:02 +0100, SF Markus Elfring wrote:
> > This is the original code:
> Really …?
> > result = baz();
> > if (result)
> > goto label;
> >
> > label:
> > go on...
>
> I do not see such a source code structure
> at the six places I propose to clean-up.
>
>
> > I don't find the test->goto label; label: use offensive,
> > but if he does, I think keeping a blank line in place of
> > the test->goto might be better.
>
> I find this an interesting view on source code layout.
> Are there any more opinions around such implementation details?

Or to put it another way, use a blank line before the
first or only label in an error/out block.

I don't find it different then commonly written blocks like:

void foo(void)
{
...;

wind1();

val = func1(...);
if (val) {
printk(...);
goto err_type;
}

wind2();

val = func2(...);
if (val) {
printk(...);
goto err_type2;
}

...

return 0;

err_type2:
unwind2();
err_type:
unwind1();
return -ERR;
}

Yes, you can elide all the blank lines, but using them can
help readability.

2015-12-15 18:27:23

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions


> rc = mdc_queue_wait(req);
> goto out;
> out:
> ptlrpc_req_finished(req);
> return rc;
> }
> ---------------------
>
> I think if the last goto out; is to be removed,
> then it should be replaced by a blank line.
>
> It separates the last operation block from the return.

Would you like to point a very specific coding style issue out?
How often should jump labels preceded with blank lines?

Regards,
Markus

2015-12-15 18:34:17

by Joe Perches

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions

On Tue, 2015-12-15 at 19:26 +0100, SF Markus Elfring wrote:
> > rc = mdc_queue_wait(req);
> > goto out;
> > out:
> > ptlrpc_req_finished(req);
> > return rc;
> > }
> > ---------------------
> >
> > I think if the last goto out; is to be removed,
> > then it should be replaced by a blank line.
> >
> > It separates the last operation block from the return.
>
> Would you like to point a very specific coding style issue out?

Other than using vertical separation can help readability?

I think there should _not_ be a hardened rule.
Style is just a guide. ?Do what you think appropriate.

> How often should jump labels preceded with blank lines?

When other nearby blocks are also separated by blank lines.

Localized consistency can be useful.

Inconsistency can make code harder to follow/predict.

2015-12-15 18:50:04

by SF Markus Elfring

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions

> I think there should _not_ be a hardened rule.

I guess that it can become hard to achieve consensus on a precise rule.


> Style is just a guide.

Generally nice ?


> Do what you think appropriate.

I'm sorry for my evolving understanding. - But I imagine that your feedback
can cause further software development troubles if the acceptance for
this update suggestion will really depend on the number of blank lines
before a jump label.

Regards,
Markus

2015-12-15 18:55:18

by Joe Perches

[permalink] [raw]
Subject: Re: staging: lustre: Delete unnecessary goto statements in six functions

On Tue, 2015-12-15 at 19:49 +0100, SF Markus Elfring wrote:
> > I think there should _not_ be a hardened rule.
> I guess that it can become hard to achieve consensus on a precise rule.

Consensus isn't unanimity.

> I imagine that your feedback
> can cause further software development troubles if the acceptance for
> this update suggestion will really depend on the number of blank lines
> before a jump label.

<shrug>

The author of any particular bit of code can do
whatever they want.

Localized consistency is probably more valuable than
global consistency.

2015-12-21 19:05:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 0/4] staging-Lustre: Fine-tuning for some function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 20:00:02 +0100

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
Delete unnecessary goto statements in six functions
Delete an unnecessary variable initialisation in mgc_process_recover_log()
Less checks in mgc_process_recover_log() after error detection
Fix a jump label position in osc_get_info()

drivers/staging/lustre/lustre/llite/namei.c | 1 -
drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ----
drivers/staging/lustre/lustre/mgc/mgc_request.c | 53 +++++++++++--------------
drivers/staging/lustre/lustre/osc/osc_request.c | 2 +-
4 files changed, 25 insertions(+), 38 deletions(-)

--
2.6.3

2015-12-21 19:09:21

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 1/4] staging: lustre: Delete unnecessary goto statements in six functions

From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:15:45 +0100

Six goto statements referred to a source code position
directly behind them.
Thus omit such unnecessary jumps.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/llite/namei.c | 1 -
drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 -------
2 files changed, 8 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 64db5e8..2113dd4 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
retval = NULL;
else
retval = dentry;
- goto out;
out:
if (req)
ptlrpc_req_finished(req);
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 294c050..920b1e9 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1181,7 +1181,6 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1216,7 +1215,6 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1282,7 +1280,6 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
out:
ptlrpc_req_finished(req);
return rc;
@@ -1362,8 +1359,6 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
-
out:
ptlrpc_req_finished(req);
return rc;
@@ -1427,8 +1422,6 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
ptlrpc_request_set_replen(req);

rc = mdc_queue_wait(req);
- goto out;
-
out:
ptlrpc_req_finished(req);
return rc;
--
2.6.3

2015-12-21 19:10:35

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 2/4] staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()

From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:24:45 +0100

The variable "mne_swab" will eventually be set to an appropriate value
from a call of the ptlrpc_rep_need_swab() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index 2c48847..da130f4 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1293,7 +1293,7 @@ static int mgc_process_recover_log(struct obd_device *obd,
struct page **pages;
int nrpages;
bool eof = true;
- bool mne_swab = false;
+ bool mne_swab;
int i;
int ealen;
int rc;
--
2.6.3

2015-12-21 19:12:26

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection

From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100

A few checks would be performed by the mgc_process_recover_log() function
even though it was determined that the passed variable "pages" contained
a null pointer or a call of the alloc_page() function failed.

1. Let us return directly if a call of the kcalloc() function failed.

2. Corresponding implementation details could be improved by adjustments
for jump targets according to the Linux coding style convention.

3. Delete sanity checks then.

4. Move an assignment for the variable "eof" behind memory allocations.

5. The variable "req" will eventually be set to an appropriate pointer
from a call of the ptlrpc_request_alloc() function.
Thus let us omit the explicit initialisation before.

6. Apply a recommendation from the script "checkpatch.pl".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/mgc/mgc_request.c | 51 +++++++++++--------------
1 file changed, 23 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index da130f4..5f581df 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -1285,14 +1285,14 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
static int mgc_process_recover_log(struct obd_device *obd,
struct config_llog_data *cld)
{
- struct ptlrpc_request *req = NULL;
+ struct ptlrpc_request *req;
struct config_llog_instance *cfg = &cld->cld_cfg;
struct mgs_config_body *body;
struct mgs_config_res *res;
struct ptlrpc_bulk_desc *desc;
struct page **pages;
int nrpages;
- bool eof = true;
+ bool eof;
bool mne_swab;
int i;
int ealen;
@@ -1309,19 +1309,18 @@ static int mgc_process_recover_log(struct obd_device *obd,
nrpages = CONFIG_READ_NRPAGES_INIT;

pages = kcalloc(nrpages, sizeof(*pages), GFP_KERNEL);
- if (pages == NULL) {
- rc = -ENOMEM;
- goto out;
- }
+ if (!pages)
+ return -ENOMEM;

for (i = 0; i < nrpages; i++) {
pages[i] = alloc_page(GFP_KERNEL);
if (pages[i] == NULL) {
rc = -ENOMEM;
- goto out;
+ goto free_pages;
}
}

+ eof = true;
again:
LASSERT(cld_is_recover(cld));
LASSERT(mutex_is_locked(&cld->cld_lock));
@@ -1329,12 +1328,12 @@ again:
&RQF_MGS_CONFIG_READ);
if (req == NULL) {
rc = -ENOMEM;
- goto out;
+ goto free_pages;
}

rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
if (rc)
- goto out;
+ goto finish_request;

/* pack request */
body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
@@ -1343,7 +1342,7 @@ again:
if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name))
>= sizeof(body->mcb_name)) {
rc = -E2BIG;
- goto out;
+ goto finish_request;
}
body->mcb_offset = cfg->cfg_last_idx + 1;
body->mcb_type = cld->cld_type;
@@ -1355,7 +1354,7 @@ again:
MGS_BULK_PORTAL);
if (desc == NULL) {
rc = -ENOMEM;
- goto out;
+ goto finish_request;
}

for (i = 0; i < nrpages; i++)
@@ -1364,12 +1363,12 @@ again:
ptlrpc_request_set_replen(req);
rc = ptlrpc_queue_wait(req);
if (rc)
- goto out;
+ goto finish_request;

res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
if (res->mcr_size < res->mcr_offset) {
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

/* always update the index even though it might have errors with
@@ -1383,18 +1382,18 @@ again:
ealen = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, 0);
if (ealen < 0) {
rc = ealen;
- goto out;
+ goto finish_request;
}

if (ealen > nrpages << PAGE_CACHE_SHIFT) {
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

if (ealen == 0) { /* no logs transferred */
if (!eof)
rc = -EINVAL;
- goto out;
+ goto finish_request;
}

mne_swab = !!ptlrpc_rep_need_swab(req);
@@ -1424,22 +1423,18 @@ again:

ealen -= PAGE_CACHE_SIZE;
}
-
-out:
- if (req)
- ptlrpc_req_finished(req);
+finish_request:
+ ptlrpc_req_finished(req);

if (rc == 0 && !eof)
goto again;
-
- if (pages) {
- for (i = 0; i < nrpages; i++) {
- if (pages[i] == NULL)
- break;
- __free_page(pages[i]);
- }
- kfree(pages);
+free_pages:
+ for (i = 0; i < nrpages; i++) {
+ if (!(pages[i]))
+ break;
+ __free_page(pages[i]);
}
+ kfree(pages);
return rc;
}

--
2.6.3

2015-12-21 19:13:33

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 4/4] staging: lustre: Fix a jump label position in osc_get_info()

From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 19:30:42 +0100

The script "checkpatch.pl" pointed out that labels should not be indented.
Thus delete a horizontal tab before the jump label "out"
in the function "osc_get_info".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/staging/lustre/lustre/osc/osc_request.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index d6c1447..85ab180 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -2727,7 +2727,7 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp,
}

*((u64 *)val) = *reply;
- out:
+out:
ptlrpc_req_finished(req);
return rc;
} else if (KEY_IS(KEY_FIEMAP)) {
--
2.6.3

2015-12-21 23:49:17

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Mon, Dec 21, 2015 at 08:12:12PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Mon, 21 Dec 2015 18:58:51 +0100
>
> A few checks would be performed by the mgc_process_recover_log() function
> even though it was determined that the passed variable "pages" contained
> a null pointer or a call of the alloc_page() function failed.
>
> 1. Let us return directly if a call of the kcalloc() function failed.
>
> 2. Corresponding implementation details could be improved by adjustments
> for jump targets according to the Linux coding style convention.
>
> 3. Delete sanity checks then.
>
> 4. Move an assignment for the variable "eof" behind memory allocations.
>
> 5. The variable "req" will eventually be set to an appropriate pointer
> from a call of the ptlrpc_request_alloc() function.
> Thus let us omit the explicit initialisation before.
>
> 6. Apply a recommendation from the script "checkpatch.pl".

That's 6 different things, shouldn't this be 6 different patches?

please redo.

thanks,

greg k-h

2015-12-22 07:16:00

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection

>> 6. Apply a recommendation from the script "checkpatch.pl".
>
> That's 6 different things, shouldn't this be 6 different patches?
>
> please redo.

Dan Carpenter requested to squash the previous update steps 5 and 6
into a single patch for better source code review.
Now I see further software development challenges to increase
the patch granularity even more as you suggest.

Which route would Lustre developers like to follow?

Regards,
Markus

2015-12-22 08:00:37

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection

On Mon, Dec 21, 2015 at 03:48:57PM -0800, Greg Kroah-Hartman wrote:
>
> That's 6 different things, shouldn't this be 6 different patches?
>

Not really. The patch could be described as just "change from using one
exit label to using several." Markus has sent a number of these patches
and I am CC'd on them because of kernel-janitors, it's really painful to
review when he breaks them up into tiny patches where he changes one
label at a time. It's like trying to put coleslaw back together into a
head of cabbage.

> On Mon, Dec 21, 2015 at 08:12:12PM +0100, SF Markus Elfring wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Mon, 21 Dec 2015 18:58:51 +0100
> >
> > A few checks would be performed by the mgc_process_recover_log() function
> > even though it was determined that the passed variable "pages" contained
> > a null pointer or a call of the alloc_page() function failed.
> >
> > 1. Let us return directly if a call of the kcalloc() function failed.
> >
> > 2. Corresponding implementation details could be improved by adjustments
> > for jump targets according to the Linux coding style convention.
> >
> > 3. Delete sanity checks then.

These are not sanity checks, of course. They were required because of a
common exit path.

> >
> > 4. Move an assignment for the variable "eof" behind memory allocations.

I had asked Markus not to do this. It is unrelated.

> >
> > 5. The variable "req" will eventually be set to an appropriate pointer
> > from a call of the ptlrpc_request_alloc() function.
> > Thus let us omit the explicit initialisation before.

Now that we use multiple labels it isn't necessary to initialize "req".

> >
> > 6. Apply a recommendation from the script "checkpatch.pl".

This is where he changed pages[i] == NULL to !(pages[i]). It's not
strictly related but it's minor and he was changing those lines anyway.

regards,
dan carpenter

2015-12-23 09:44:20

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] block-LDM: One function call less in ldm_validate_tocblocks() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100

This issue was detected by using the Coccinelle software.

Let us return directly if a memory allocation failed.

Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index e507cfb..a50385c 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
tb[1] = kmalloc(sizeof(*tb[1]) * 3, GFP_KERNEL);
if (!tb[1]) {
ldm_crit("Out of memory.");
- goto err;
+ return false;
}
tb[2] = (struct tocblock*)((u8*)tb[1] + sizeof(*tb[1]));
tb[3] = (struct tocblock*)((u8*)tb[2] + sizeof(*tb[2]));
--
2.6.3

2015-12-23 10:41:55

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH] block-LDM: One function call less in ldm_validate_tocblocks() after error detection



On Wed, 23 Dec 2015, SF Markus Elfring wrote:

> From: Markus Elfring <[email protected]>
> Date: Tue, 22 Dec 2015 22:32:07 +0100
>
> This issue was detected by using the Coccinelle software.
>
> Let us return directly if a memory allocation failed.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> block/partitions/ldm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
> index e507cfb..a50385c 100644
> --- a/block/partitions/ldm.c
> +++ b/block/partitions/ldm.c
> @@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
> tb[1] = kmalloc(sizeof(*tb[1]) * 3, GFP_KERNEL);
> if (!tb[1]) {
> ldm_crit("Out of memory.");
> - goto err;
> + return false;

The ldm_crit, which is just a printk, is also not necessary, because
kmalloc already generates backtrace information on failure. So you could
clean up the whole thing at once.

julia

> }
> tb[2] = (struct tocblock*)((u8*)tb[1] + sizeof(*tb[1]));
> tb[3] = (struct tocblock*)((u8*)tb[2] + sizeof(*tb[2]));
> --
> 2.6.3
>
>

2015-12-23 18:03:04

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/5] block-LDM: Improvements for exception handling

From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 17:32:12 +0100

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
One function call less in ldm_validate_tocblocks() after error detection
Delete extra log messages for memory allocation failures
One function call less in ldm_partition() after error detection
Less function calls in ldm_validate_privheads() after error detection
Fine-tuning for the source code formatting

block/partitions/ldm.c | 455 +++++++++++++++++++++++++------------------------
1 file changed, 236 insertions(+), 219 deletions(-)

--
2.6.3

2015-12-23 18:06:50

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/5] block-LDM: One function call less in ldm_validate_tocblocks() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100

This issue was detected by using the Coccinelle software.

Let us return directly if a memory allocation failed.

Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index e507cfb..a50385c 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -433,7 +433,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
tb[1] = kmalloc(sizeof(*tb[1]) * 3, GFP_KERNEL);
if (!tb[1]) {
ldm_crit("Out of memory.");
- goto err;
+ return false;
}
tb[2] = (struct tocblock*)((u8*)tb[1] + sizeof(*tb[1]));
tb[3] = (struct tocblock*)((u8*)tb[2] + sizeof(*tb[2]));
--
2.6.3

2015-12-23 18:09:26

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/5] block-LDM: Delete extra log messages for memory allocation failures

From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 13:21:01 +0100

A failed call of the kmalloc() function can generate appropriate
information about insufficient memory already.
Thus remove unnecessary log messages for such failures.

Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index a50385c..856658a 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -343,10 +343,8 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,

ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
- if (!ph[1] || !ph[2]) {
- ldm_crit ("Out of memory.");
+ if (!ph[1] || !ph[2])
goto out;
- }

/* off[1 & 2] are relative to ph[0]->config_start */
ph[0]->config_start = 0;
@@ -431,10 +429,8 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
ph = &ldb->ph;
tb[0] = &ldb->toc;
tb[1] = kmalloc(sizeof(*tb[1]) * 3, GFP_KERNEL);
- if (!tb[1]) {
- ldm_crit("Out of memory.");
+ if (!tb[1])
return false;
- }
tb[2] = (struct tocblock*)((u8*)tb[1] + sizeof(*tb[1]));
tb[3] = (struct tocblock*)((u8*)tb[2] + sizeof(*tb[2]));
/*
@@ -1239,10 +1235,8 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)
BUG_ON (!data || !ldb);

vb = kmalloc (sizeof (*vb), GFP_KERNEL);
- if (!vb) {
- ldm_crit ("Out of memory.");
+ if (!vb)
return false;
- }

if (!ldm_parse_vblk (data, len, vb)) {
kfree(vb);
@@ -1325,10 +1319,8 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
}

f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
- if (!f) {
- ldm_crit ("Out of memory.");
+ if (!f)
return false;
- }

f->group = group;
f->num = num;
@@ -1519,10 +1511,8 @@ int ldm_partition(struct parsed_partitions *state)
return 0;

ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
- if (!ldb) {
- ldm_crit ("Out of memory.");
+ if (!ldb)
goto out;
- }

/* Parse and check privheads. */
if (!ldm_validate_privheads(state, &ldb->ph))
--
2.6.3

2015-12-23 18:10:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/5] block-LDM: One function call less in ldm_partition() after error detection

From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 13:32:51 +0100

Let us return directly if a memory allocation failed.

Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 856658a..3118d24 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -1512,7 +1512,7 @@ int ldm_partition(struct parsed_partitions *state)

ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
if (!ldb)
- goto out;
+ return -1;

/* Parse and check privheads. */
if (!ldm_validate_privheads(state, &ldb->ph))
--
2.6.3

2015-12-23 18:12:29

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/5] block-LDM: Less function calls in ldm_validate_privheads() after error detection

From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 14:31:01 +0100

The kfree() function was called by the ldm_validate_privheads() function
during error handling even if the passed variable "ph" contained
a null pointer.

* Corresponding implementation details could be improved by adjustments
for jump targets according to the Linux coding style convention.

* The variable "result" will eventually be set to an appropriate value.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 3118d24..6fc9150 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -335,16 +335,20 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
struct privhead *ph[3] = { ph1 };
Sector sect;
u8 *data;
- bool result = false;
+ bool result;
long num_sects;
int i;

BUG_ON (!state || !ph1);

ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
+ if (!ph[1])
+ return false;
ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
- if (!ph[1] || !ph[2])
- goto out;
+ if (!ph[2]) {
+ result = false;
+ goto free_a_head;
+ }

/* off[1 & 2] are relative to ph[0]->config_start */
ph[0]->config_start = 0;
@@ -355,14 +359,15 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
&sect);
if (!data) {
ldm_crit ("Disk read failed.");
- goto out;
+ result = false;
+ goto free_another_head;
}
result = ldm_parse_privhead (data, ph[i]);
put_dev_sector (sect);
if (!result) {
ldm_error ("Cannot find PRIVHEAD %d.", i+1); /* Log again */
if (i < 2)
- goto out; /* Already logged */
+ goto free_another_head; /* Already logged */
else
break; /* FIXME ignore for now, 3rd PH can fail on odd-sized disks */
}
@@ -373,30 +378,31 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
if ((ph[0]->config_start > num_sects) ||
((ph[0]->config_start + ph[0]->config_size) > num_sects)) {
ldm_crit ("Database extends beyond the end of the disk.");
- goto out;
+ goto free_another_head;
}

if ((ph[0]->logical_disk_start > ph[0]->config_start) ||
((ph[0]->logical_disk_start + ph[0]->logical_disk_size)
> ph[0]->config_start)) {
ldm_crit ("Disk and database overlap.");
- goto out;
+ goto free_another_head;
}

if (!ldm_compare_privheads (ph[0], ph[1])) {
ldm_crit ("Primary and backup PRIVHEADs don't match.");
- goto out;
+ goto free_another_head;
}
/* FIXME ignore this for now
if (!ldm_compare_privheads (ph[0], ph[2])) {
ldm_crit ("Primary and backup PRIVHEADs don't match.");
- goto out;
+ goto free_another_head;
}*/
ldm_debug ("Validated PRIVHEADs successfully.");
result = true;
-out:
- kfree (ph[1]);
- kfree (ph[2]);
+free_another_head:
+ kfree(ph[2]);
+free_a_head:
+ kfree(ph[1]);
return result;
}

--
2.6.3

2015-12-23 18:14:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/5] block-LDM: Fine-tuning for the source code formatting

From: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 17:23:25 +0100

1. Remove some space characters and add a few according to the Linux coding
style convention.

2. Reformat a bit of source code also for one switch statement.

3. Apply a few more recommendations from the script "checkpatch.pl".

Signed-off-by: Markus Elfring <[email protected]>
---
block/partitions/ldm.c | 405 ++++++++++++++++++++++++++-----------------------
1 file changed, 213 insertions(+), 192 deletions(-)

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 6fc9150..3ebe033 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -42,12 +42,12 @@
#ifndef CONFIG_LDM_DEBUG
#define ldm_debug(...) do {} while (0)
#else
-#define ldm_debug(f, a...) _ldm_printk (KERN_DEBUG, __func__, f, ##a)
+#define ldm_debug(f, a...) _ldm_printk(KERN_DEBUG, __func__, f, ##a)
#endif

-#define ldm_crit(f, a...) _ldm_printk (KERN_CRIT, __func__, f, ##a)
-#define ldm_error(f, a...) _ldm_printk (KERN_ERR, __func__, f, ##a)
-#define ldm_info(f, a...) _ldm_printk (KERN_INFO, __func__, f, ##a)
+#define ldm_crit(f, a...) _ldm_printk(KERN_CRIT, __func__, f, ##a)
+#define ldm_error(f, a...) _ldm_printk(KERN_ERR, __func__, f, ##a)
+#define ldm_info(f, a...) _ldm_printk(KERN_INFO, __func__, f, ##a)

static __printf(3, 4)
void _ldm_printk(const char *level, const char *function, const char *fmt, ...)
@@ -55,7 +55,7 @@ void _ldm_printk(const char *level, const char *function, const char *fmt, ...)
struct va_format vaf;
va_list args;

- va_start (args, fmt);
+ va_start(args, fmt);

vaf.fmt = fmt;
vaf.va = &args;
@@ -74,7 +74,7 @@ void _ldm_printk(const char *level, const char *function, const char *fmt, ...)
* Return: 0-255 Success, the byte was parsed correctly
* -1 Error, an invalid character was supplied
*/
-static int ldm_parse_hexbyte (const u8 *src)
+static int ldm_parse_hexbyte(const u8 *src)
{
unsigned int x; /* For correct wrapping */
int h;
@@ -102,7 +102,7 @@ static int ldm_parse_hexbyte (const u8 *src)
* Return: 'true' @dest contains binary GUID
* 'false' @dest contents are undefined
*/
-static bool ldm_parse_guid (const u8 *src, u8 *dest)
+static bool ldm_parse_guid(const u8 *src, u8 *dest)
{
static const int size[] = { 4, 2, 2, 2, 6 };
int i, j, v;
@@ -112,10 +112,11 @@ static bool ldm_parse_guid (const u8 *src, u8 *dest)
return false;

for (j = 0; j < 5; j++, src++)
- for (i = 0; i < size[j]; i++, src+=2, *dest++ = v)
- if ((v = ldm_parse_hexbyte (src)) < 0)
+ for (i = 0; i < size[j]; i++, src += 2, *dest++ = v) {
+ v = ldm_parse_hexbyte(src);
+ if (v < 0)
return false;
-
+ }
return true;
}

@@ -189,36 +190,36 @@ static bool ldm_parse_privhead(const u8 *data, struct privhead *ph)
* Return: 'true' @toc contains the TOCBLOCK data
* 'false' @toc contents are undefined
*/
-static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc)
+static bool ldm_parse_tocblock(const u8 *data, struct tocblock *toc)
{
- BUG_ON (!data || !toc);
+ BUG_ON(!data || !toc);

if (MAGIC_TOCBLOCK != get_unaligned_be64(data)) {
- ldm_crit ("Cannot find TOCBLOCK, database may be corrupt.");
+ ldm_crit("Cannot find TOCBLOCK, database may be corrupt.");
return false;
}
- strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name));
+ strncpy(toc->bitmap1_name, data + 0x24, sizeof(toc->bitmap1_name));
toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = 0;
toc->bitmap1_start = get_unaligned_be64(data + 0x2E);
toc->bitmap1_size = get_unaligned_be64(data + 0x36);

- if (strncmp (toc->bitmap1_name, TOC_BITMAP1,
- sizeof (toc->bitmap1_name)) != 0) {
- ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'.",
+ if (strncmp(toc->bitmap1_name, TOC_BITMAP1,
+ sizeof(toc->bitmap1_name)) != 0) {
+ ldm_crit("TOCBLOCK's first bitmap is '%s', should be '%s'.",
TOC_BITMAP1, toc->bitmap1_name);
return false;
}
- strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name));
- toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = 0;
+ strncpy(toc->bitmap2_name, data + 0x46, sizeof(toc->bitmap2_name));
+ toc->bitmap2_name[sizeof(toc->bitmap2_name) - 1] = 0;
toc->bitmap2_start = get_unaligned_be64(data + 0x50);
toc->bitmap2_size = get_unaligned_be64(data + 0x58);
- if (strncmp (toc->bitmap2_name, TOC_BITMAP2,
- sizeof (toc->bitmap2_name)) != 0) {
- ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'.",
+ if (strncmp(toc->bitmap2_name, TOC_BITMAP2,
+ sizeof(toc->bitmap2_name)) != 0) {
+ ldm_crit("TOCBLOCK's second bitmap is '%s', should be '%s'.",
TOC_BITMAP2, toc->bitmap2_name);
return false;
}
- ldm_debug ("Parsed TOCBLOCK successfully.");
+ ldm_debug("Parsed TOCBLOCK successfully.");
return true;
}

@@ -235,33 +236,33 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc)
* Return: 'true' @vm contains VMDB info
* 'false' @vm contents are undefined
*/
-static bool ldm_parse_vmdb (const u8 *data, struct vmdb *vm)
+static bool ldm_parse_vmdb(const u8 *data, struct vmdb *vm)
{
- BUG_ON (!data || !vm);
+ BUG_ON(!data || !vm);

if (MAGIC_VMDB != get_unaligned_be32(data)) {
- ldm_crit ("Cannot find the VMDB, database may be corrupt.");
+ ldm_crit("Cannot find the VMDB, database may be corrupt.");
return false;
}

vm->ver_major = get_unaligned_be16(data + 0x12);
vm->ver_minor = get_unaligned_be16(data + 0x14);
if ((vm->ver_major != 4) || (vm->ver_minor != 10)) {
- ldm_error ("Expected VMDB version %d.%d, got %d.%d. "
+ ldm_error("Expected VMDB version %d.%d, got %d.%d. "
"Aborting.", 4, 10, vm->ver_major, vm->ver_minor);
return false;
}

vm->vblk_size = get_unaligned_be32(data + 0x08);
if (vm->vblk_size == 0) {
- ldm_error ("Illegal VBLK size");
+ ldm_error("Illegal VBLK size");
return false;
}

vm->vblk_offset = get_unaligned_be32(data + 0x0C);
vm->last_vblk_seq = get_unaligned_be32(data + 0x04);

- ldm_debug ("Parsed VMDB successfully.");
+ ldm_debug("Parsed VMDB successfully.");
return true;
}

@@ -275,10 +276,10 @@ static bool ldm_parse_vmdb (const u8 *data, struct vmdb *vm)
* Return: 'true' Identical
* 'false' Different
*/
-static bool ldm_compare_privheads (const struct privhead *ph1,
+static bool ldm_compare_privheads(const struct privhead *ph1,
const struct privhead *ph2)
{
- BUG_ON (!ph1 || !ph2);
+ BUG_ON(!ph1 || !ph2);

return ((ph1->ver_major == ph2->ver_major) &&
(ph1->ver_minor == ph2->ver_minor) &&
@@ -286,7 +287,7 @@ static bool ldm_compare_privheads (const struct privhead *ph1,
(ph1->logical_disk_size == ph2->logical_disk_size) &&
(ph1->config_start == ph2->config_start) &&
(ph1->config_size == ph2->config_size) &&
- !memcmp (ph1->disk_id, ph2->disk_id, GUID_SIZE));
+ !memcmp(ph1->disk_id, ph2->disk_id, GUID_SIZE));
}

/**
@@ -299,19 +300,19 @@ static bool ldm_compare_privheads (const struct privhead *ph1,
* Return: 'true' Identical
* 'false' Different
*/
-static bool ldm_compare_tocblocks (const struct tocblock *toc1,
+static bool ldm_compare_tocblocks(const struct tocblock *toc1,
const struct tocblock *toc2)
{
- BUG_ON (!toc1 || !toc2);
+ BUG_ON(!toc1 || !toc2);

return ((toc1->bitmap1_start == toc2->bitmap1_start) &&
(toc1->bitmap1_size == toc2->bitmap1_size) &&
(toc1->bitmap2_start == toc2->bitmap2_start) &&
(toc1->bitmap2_size == toc2->bitmap2_size) &&
- !strncmp (toc1->bitmap1_name, toc2->bitmap1_name,
- sizeof (toc1->bitmap1_name)) &&
- !strncmp (toc1->bitmap2_name, toc2->bitmap2_name,
- sizeof (toc1->bitmap2_name)));
+ !strncmp(toc1->bitmap1_name, toc2->bitmap1_name,
+ sizeof(toc1->bitmap1_name)) &&
+ !strncmp(toc1->bitmap2_name, toc2->bitmap2_name,
+ sizeof(toc1->bitmap2_name)));
}

/**
@@ -339,12 +340,12 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
long num_sects;
int i;

- BUG_ON (!state || !ph1);
+ BUG_ON(!state || !ph1);

- ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
+ ph[1] = kmalloc(sizeof(*ph[1]), GFP_KERNEL);
if (!ph[1])
return false;
- ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
+ ph[2] = kmalloc(sizeof(*ph[2]), GFP_KERNEL);
if (!ph[2]) {
result = false;
goto free_a_head;
@@ -358,18 +359,23 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
data = read_part_sector(state, ph[0]->config_start + off[i],
&sect);
if (!data) {
- ldm_crit ("Disk read failed.");
+ ldm_crit("Disk read failed.");
result = false;
goto free_another_head;
}
- result = ldm_parse_privhead (data, ph[i]);
+ result = ldm_parse_privhead(data, ph[i]);
put_dev_sector (sect);
if (!result) {
- ldm_error ("Cannot find PRIVHEAD %d.", i+1); /* Log again */
+ /* Log again */
+ ldm_error("Cannot find PRIVHEAD %d.", i + 1);
if (i < 2)
goto free_another_head; /* Already logged */
else
- break; /* FIXME ignore for now, 3rd PH can fail on odd-sized disks */
+ /*
+ * FIXME: ignore for now,
+ * 3rd PH can fail on odd-sized disks
+ */
+ break;
}
}

@@ -377,19 +383,19 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,

if ((ph[0]->config_start > num_sects) ||
((ph[0]->config_start + ph[0]->config_size) > num_sects)) {
- ldm_crit ("Database extends beyond the end of the disk.");
+ ldm_crit("Database extends beyond the end of the disk.");
goto free_another_head;
}

if ((ph[0]->logical_disk_start > ph[0]->config_start) ||
((ph[0]->logical_disk_start + ph[0]->logical_disk_size)
> ph[0]->config_start)) {
- ldm_crit ("Disk and database overlap.");
+ ldm_crit("Disk and database overlap.");
goto free_another_head;
}

- if (!ldm_compare_privheads (ph[0], ph[1])) {
- ldm_crit ("Primary and backup PRIVHEADs don't match.");
+ if (!ldm_compare_privheads(ph[0], ph[1])) {
+ ldm_crit("Primary and backup PRIVHEADs don't match.");
goto free_another_head;
}
/* FIXME ignore this for now
@@ -397,7 +403,7 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
ldm_crit ("Primary and backup PRIVHEADs don't match.");
goto free_another_head;
}*/
- ldm_debug ("Validated PRIVHEADs successfully.");
+ ldm_debug("Validated PRIVHEADs successfully.");
result = true;
free_another_head:
kfree(ph[2]);
@@ -501,42 +507,42 @@ static bool ldm_validate_vmdb(struct parsed_partitions *state,
struct vmdb *vm;
struct tocblock *toc;

- BUG_ON (!state || !ldb);
+ BUG_ON(!state || !ldb);

vm = &ldb->vm;
toc = &ldb->toc;

data = read_part_sector(state, base + OFF_VMDB, &sect);
if (!data) {
- ldm_crit ("Disk read failed.");
+ ldm_crit("Disk read failed.");
return false;
}

- if (!ldm_parse_vmdb (data, vm))
+ if (!ldm_parse_vmdb(data, vm))
goto out; /* Already logged */

/* Are there uncommitted transactions? */
if (get_unaligned_be16(data + 0x10) != 0x01) {
- ldm_crit ("Database is not in a consistent state. Aborting.");
+ ldm_crit("Database is not in a consistent state. Aborting.");
goto out;
}

if (vm->vblk_offset != 512)
- ldm_info ("VBLKs start at offset 0x%04x.", vm->vblk_offset);
+ ldm_info("VBLKs start at offset 0x%04x.", vm->vblk_offset);

/*
* The last_vblkd_seq can be before the end of the vmdb, just make sure
* it is not out of bounds.
*/
if ((vm->vblk_size * vm->last_vblk_seq) > (toc->bitmap1_size << 9)) {
- ldm_crit ("VMDB exceeds allowed size specified by TOCBLOCK. "
+ ldm_crit("VMDB exceeds allowed size specified by TOCBLOCK. "
"Database is corrupt. Aborting.");
goto out;
}

result = true;
out:
- put_dev_sector (sect);
+ put_dev_sector(sect);
return result;
}

@@ -569,11 +575,11 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state)

data = read_part_sector(state, 0, &sect);
if (!data) {
- ldm_info ("Disk read failed.");
+ ldm_info("Disk read failed.");
return false;
}

- if (*(__le16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC))
+ if (*(__le16 *) (data + 0x01FE) != cpu_to_le16(MSDOS_LABEL_MAGIC))
goto out;

p = (struct partition*)(data + 0x01BE);
@@ -584,10 +590,10 @@ static bool ldm_validate_partition_table(struct parsed_partitions *state)
}

if (result)
- ldm_debug ("Found W2K dynamic disk partition type.");
+ ldm_debug("Found W2K dynamic disk partition type.");

out:
- put_dev_sector (sect);
+ put_dev_sector(sect);
return result;
}

@@ -603,15 +609,16 @@ out:
* Return: Pointer, A matching vblk was found
* NULL, No match, or an error
*/
-static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb)
+static struct vblk *ldm_get_disk_objid(const struct ldmdb *ldb)
{
struct list_head *item;

- BUG_ON (!ldb);
+ BUG_ON(!ldb);

- list_for_each (item, &ldb->v_disk) {
- struct vblk *v = list_entry (item, struct vblk, list);
- if (!memcmp (v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE))
+ list_for_each(item, &ldb->v_disk) {
+ struct vblk *v = list_entry(item, struct vblk, list);
+
+ if (!memcmp(v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE))
return v;
}

@@ -635,7 +642,7 @@ static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb)
* Return: 'true' Partition created
* 'false' Error, probably a range checking problem
*/
-static bool ldm_create_data_partitions (struct parsed_partitions *pp,
+static bool ldm_create_data_partitions(struct parsed_partitions *pp,
const struct ldmdb *ldb)
{
struct list_head *item;
@@ -644,25 +651,25 @@ static bool ldm_create_data_partitions (struct parsed_partitions *pp,
struct vblk_part *part;
int part_num = 1;

- BUG_ON (!pp || !ldb);
+ BUG_ON(!pp || !ldb);

- disk = ldm_get_disk_objid (ldb);
+ disk = ldm_get_disk_objid(ldb);
if (!disk) {
- ldm_crit ("Can't find the ID of this disk in the database.");
+ ldm_crit("Can't find the ID of this disk in the database.");
return false;
}

strlcat(pp->pp_buf, " [LDM]", PAGE_SIZE);

/* Create the data partitions */
- list_for_each (item, &ldb->v_part) {
- vb = list_entry (item, struct vblk, list);
+ list_for_each(item, &ldb->v_part) {
+ vb = list_entry(item, struct vblk, list);
part = &vb->vblk.part;

if (part->disk_id != disk->obj_id)
continue;

- put_partition (pp, part_num, ldb->ph.logical_disk_start +
+ put_partition(pp, part_num, ldb->ph.logical_disk_start +
part->start, part->size);
part_num++;
}
@@ -722,12 +729,12 @@ static int ldm_relative(const u8 *buffer, int buflen, int base, int offset)
* Return: n A number
* 0 Zero, or an error occurred
*/
-static u64 ldm_get_vnum (const u8 *block)
+static u64 ldm_get_vnum(const u8 *block)
{
u64 tmp = 0;
u8 length;

- BUG_ON (!block);
+ BUG_ON(!block);

length = *block++;

@@ -735,7 +742,7 @@ static u64 ldm_get_vnum (const u8 *block)
while (length--)
tmp = (tmp << 8) | *block++;
else
- ldm_error ("Illegal length %d.", length);
+ ldm_error("Illegal length %d.", length);

return tmp;
}
@@ -757,18 +764,18 @@ static u64 ldm_get_vnum (const u8 *block)
* n, String length in characters (excluding NULL)
* buflen-1, String was truncated.
*/
-static int ldm_get_vstr (const u8 *block, u8 *buffer, int buflen)
+static int ldm_get_vstr(const u8 *block, u8 *buffer, int buflen)
{
int length;

- BUG_ON (!block || !buffer);
+ BUG_ON(!block || !buffer);

length = block[0];
if (length >= buflen) {
- ldm_error ("Truncating string %d -> %d.", length, buflen);
+ ldm_error("Truncating string %d -> %d.", length, buflen);
length = buflen - 1;
}
- memcpy (buffer, block + 1, length);
+ memcpy(buffer, block + 1, length);
buffer[length] = 0;
return length;
}
@@ -785,22 +792,22 @@ static int ldm_get_vstr (const u8 *block, u8 *buffer, int buflen)
* Return: 'true' @vb contains a Component VBLK
* 'false' @vb contents are not defined
*/
-static bool ldm_parse_cmp3 (const u8 *buffer, int buflen, struct vblk *vb)
+static bool ldm_parse_cmp3(const u8 *buffer, int buflen, struct vblk *vb)
{
int r_objid, r_name, r_vstate, r_child, r_parent, r_stripe, r_cols, len;
struct vblk_comp *comp;

- BUG_ON (!buffer || !vb);
+ BUG_ON(!buffer || !vb);

- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
- r_vstate = ldm_relative (buffer, buflen, 0x18, r_name);
- r_child = ldm_relative (buffer, buflen, 0x1D, r_vstate);
- r_parent = ldm_relative (buffer, buflen, 0x2D, r_child);
+ r_objid = ldm_relative(buffer, buflen, 0x18, 0);
+ r_name = ldm_relative(buffer, buflen, 0x18, r_objid);
+ r_vstate = ldm_relative(buffer, buflen, 0x18, r_name);
+ r_child = ldm_relative(buffer, buflen, 0x1D, r_vstate);
+ r_parent = ldm_relative(buffer, buflen, 0x2D, r_child);

if (buffer[0x12] & VBLK_FLAG_COMP_STRIPE) {
- r_stripe = ldm_relative (buffer, buflen, 0x2E, r_parent);
- r_cols = ldm_relative (buffer, buflen, 0x2E, r_stripe);
+ r_stripe = ldm_relative(buffer, buflen, 0x2E, r_parent);
+ r_cols = ldm_relative(buffer, buflen, 0x2E, r_stripe);
len = r_cols;
} else {
r_stripe = 0;
@@ -815,12 +822,12 @@ static bool ldm_parse_cmp3 (const u8 *buffer, int buflen, struct vblk *vb)
return false;

comp = &vb->vblk.comp;
- ldm_get_vstr (buffer + 0x18 + r_name, comp->state,
- sizeof (comp->state));
+ ldm_get_vstr(buffer + 0x18 + r_name, comp->state,
+ sizeof(comp->state));
comp->type = buffer[0x18 + r_vstate];
- comp->children = ldm_get_vnum (buffer + 0x1D + r_vstate);
- comp->parent_id = ldm_get_vnum (buffer + 0x2D + r_child);
- comp->chunksize = r_stripe ? ldm_get_vnum (buffer+r_parent+0x2E) : 0;
+ comp->children = ldm_get_vnum(buffer + 0x1D + r_vstate);
+ comp->parent_id = ldm_get_vnum(buffer + 0x2D + r_child);
+ comp->chunksize = r_stripe ? ldm_get_vnum(buffer + r_parent + 0x2E) : 0;

return true;
}
@@ -836,20 +843,20 @@ static bool ldm_parse_cmp3 (const u8 *buffer, int buflen, struct vblk *vb)
* Return: 'true' @vb contains a Disk Group VBLK
* 'false' @vb contents are not defined
*/
-static int ldm_parse_dgr3 (const u8 *buffer, int buflen, struct vblk *vb)
+static int ldm_parse_dgr3(const u8 *buffer, int buflen, struct vblk *vb)
{
int r_objid, r_name, r_diskid, r_id1, r_id2, len;
struct vblk_dgrp *dgrp;

- BUG_ON (!buffer || !vb);
+ BUG_ON(!buffer || !vb);

- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
- r_diskid = ldm_relative (buffer, buflen, 0x18, r_name);
+ r_objid = ldm_relative(buffer, buflen, 0x18, 0);
+ r_name = ldm_relative(buffer, buflen, 0x18, r_objid);
+ r_diskid = ldm_relative(buffer, buflen, 0x18, r_name);

if (buffer[0x12] & VBLK_FLAG_DGR3_IDS) {
- r_id1 = ldm_relative (buffer, buflen, 0x24, r_diskid);
- r_id2 = ldm_relative (buffer, buflen, 0x24, r_id1);
+ r_id1 = ldm_relative(buffer, buflen, 0x24, r_diskid);
+ r_id2 = ldm_relative(buffer, buflen, 0x24, r_id1);
len = r_id2;
} else {
r_id1 = 0;
@@ -864,8 +871,8 @@ static int ldm_parse_dgr3 (const u8 *buffer, int buflen, struct vblk *vb)
return false;

dgrp = &vb->vblk.dgrp;
- ldm_get_vstr (buffer + 0x18 + r_name, dgrp->disk_id,
- sizeof (dgrp->disk_id));
+ ldm_get_vstr(buffer + 0x18 + r_name, dgrp->disk_id,
+ sizeof(dgrp->disk_id));
return true;
}

@@ -886,14 +893,14 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb)
int r_objid, r_name, r_id1, r_id2, len;
struct vblk_dgrp *dgrp;

- BUG_ON (!buffer || !vb);
+ BUG_ON(!buffer || !vb);

- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
+ r_objid = ldm_relative(buffer, buflen, 0x18, 0);
+ r_name = ldm_relative(buffer, buflen, 0x18, r_objid);

if (buffer[0x12] & VBLK_FLAG_DGR4_IDS) {
- r_id1 = ldm_relative (buffer, buflen, 0x44, r_name);
- r_id2 = ldm_relative (buffer, buflen, 0x44, r_id1);
+ r_id1 = ldm_relative(buffer, buflen, 0x44, r_name);
+ r_id2 = ldm_relative(buffer, buflen, 0x44, r_id1);
len = r_id2;
} else {
r_id1 = 0;
@@ -909,7 +916,7 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb)

dgrp = &vb->vblk.dgrp;

- ldm_get_vstr (buffer + 0x18 + r_objid, buf, sizeof (buf));
+ ldm_get_vstr(buffer + 0x18 + r_objid, buf, sizeof(buf));
return true;
}

@@ -924,17 +931,17 @@ static bool ldm_parse_dgr4 (const u8 *buffer, int buflen, struct vblk *vb)
* Return: 'true' @vb contains a Disk VBLK
* 'false' @vb contents are not defined
*/
-static bool ldm_parse_dsk3 (const u8 *buffer, int buflen, struct vblk *vb)
+static bool ldm_parse_dsk3(const u8 *buffer, int buflen, struct vblk *vb)
{
int r_objid, r_name, r_diskid, r_altname, len;
struct vblk_disk *disk;

- BUG_ON (!buffer || !vb);
+ BUG_ON(!buffer || !vb);

- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
- r_diskid = ldm_relative (buffer, buflen, 0x18, r_name);
- r_altname = ldm_relative (buffer, buflen, 0x18, r_diskid);
+ r_objid = ldm_relative(buffer, buflen, 0x18, 0);
+ r_name = ldm_relative(buffer, buflen, 0x18, r_objid);
+ r_diskid = ldm_relative(buffer, buflen, 0x18, r_name);
+ r_altname = ldm_relative(buffer, buflen, 0x18, r_diskid);
len = r_altname;
if (len < 0)
return false;
@@ -944,9 +951,9 @@ static bool ldm_parse_dsk3 (const u8 *buffer, int buflen, struct vblk *vb)
return false;

disk = &vb->vblk.disk;
- ldm_get_vstr (buffer + 0x18 + r_diskid, disk->alt_name,
- sizeof (disk->alt_name));
- if (!ldm_parse_guid (buffer + 0x19 + r_name, disk->disk_id))
+ ldm_get_vstr(buffer + 0x18 + r_diskid, disk->alt_name,
+ sizeof(disk->alt_name));
+ if (!ldm_parse_guid(buffer + 0x19 + r_name, disk->disk_id))
return false;

return true;
@@ -963,15 +970,15 @@ static bool ldm_parse_dsk3 (const u8 *buffer, int buflen, struct vblk *vb)
* Return: 'true' @vb contains a Disk VBLK
* 'false' @vb contents are not defined
*/
-static bool ldm_parse_dsk4 (const u8 *buffer, int buflen, struct vblk *vb)
+static bool ldm_parse_dsk4(const u8 *buffer, int buflen, struct vblk *vb)
{
int r_objid, r_name, len;
struct vblk_disk *disk;

- BUG_ON (!buffer || !vb);
+ BUG_ON(!buffer || !vb);

- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
+ r_objid = ldm_relative(buffer, buflen, 0x18, 0);
+ r_name = ldm_relative(buffer, buflen, 0x18, r_objid);
len = r_name;
if (len < 0)
return false;
@@ -981,7 +988,7 @@ static bool ldm_parse_dsk4 (const u8 *buffer, int buflen, struct vblk *vb)
return false;

disk = &vb->vblk.disk;
- memcpy (disk->disk_id, buffer + 0x18 + r_name, GUID_SIZE);
+ memcpy(disk->disk_id, buffer + 0x18 + r_name, GUID_SIZE);
return true;
}

@@ -1181,39 +1188,53 @@ static bool ldm_parse_vol5(const u8 *buffer, int buflen, struct vblk *vb)
* Return: 'true' @vb contains a VBLK
* 'false' @vb contents are not defined
*/
-static bool ldm_parse_vblk (const u8 *buf, int len, struct vblk *vb)
+static bool ldm_parse_vblk(const u8 *buf, int len, struct vblk *vb)
{
bool result = false;
int r_objid;

- BUG_ON (!buf || !vb);
+ BUG_ON(!buf || !vb);

- r_objid = ldm_relative (buf, len, 0x18, 0);
+ r_objid = ldm_relative(buf, len, 0x18, 0);
if (r_objid < 0) {
- ldm_error ("VBLK header is corrupt.");
+ ldm_error("VBLK header is corrupt.");
return false;
}

vb->flags = buf[0x12];
vb->type = buf[0x13];
- vb->obj_id = ldm_get_vnum (buf + 0x18);
- ldm_get_vstr (buf+0x18+r_objid, vb->name, sizeof (vb->name));
+ vb->obj_id = ldm_get_vnum(buf + 0x18);
+ ldm_get_vstr(buf + 0x18 + r_objid, vb->name, sizeof(vb->name));

switch (vb->type) {
- case VBLK_CMP3: result = ldm_parse_cmp3 (buf, len, vb); break;
- case VBLK_DSK3: result = ldm_parse_dsk3 (buf, len, vb); break;
- case VBLK_DSK4: result = ldm_parse_dsk4 (buf, len, vb); break;
- case VBLK_DGR3: result = ldm_parse_dgr3 (buf, len, vb); break;
- case VBLK_DGR4: result = ldm_parse_dgr4 (buf, len, vb); break;
- case VBLK_PRT3: result = ldm_parse_prt3 (buf, len, vb); break;
- case VBLK_VOL5: result = ldm_parse_vol5 (buf, len, vb); break;
+ case VBLK_CMP3:
+ result = ldm_parse_cmp3(buf, len, vb);
+ break;
+ case VBLK_DSK3:
+ result = ldm_parse_dsk3(buf, len, vb);
+ break;
+ case VBLK_DSK4:
+ result = ldm_parse_dsk4(buf, len, vb);
+ break;
+ case VBLK_DGR3:
+ result = ldm_parse_dgr3(buf, len, vb);
+ break;
+ case VBLK_DGR4:
+ result = ldm_parse_dgr4(buf, len, vb);
+ break;
+ case VBLK_PRT3:
+ result = ldm_parse_prt3(buf, len, vb);
+ break;
+ case VBLK_VOL5:
+ result = ldm_parse_vol5(buf, len, vb);
+ break;
}

if (result)
- ldm_debug ("Parsed VBLK 0x%llx (type: 0x%02x) ok.",
+ ldm_debug("Parsed VBLK 0x%llx (type: 0x%02x) ok.",
(unsigned long long) vb->obj_id, vb->type);
else
- ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x).",
+ ldm_error("Failed to parse VBLK 0x%llx (type: 0x%02x).",
(unsigned long long) vb->obj_id, vb->type);

return result;
@@ -1238,13 +1259,13 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)
struct vblk *vb;
struct list_head *item;

- BUG_ON (!data || !ldb);
+ BUG_ON(!data || !ldb);

- vb = kmalloc (sizeof (*vb), GFP_KERNEL);
+ vb = kmalloc(sizeof(*vb), GFP_KERNEL);
if (!vb)
return false;

- if (!ldm_parse_vblk (data, len, vb)) {
+ if (!ldm_parse_vblk(data, len, vb)) {
kfree(vb);
return false; /* Already logged */
}
@@ -1253,29 +1274,29 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)
switch (vb->type) {
case VBLK_DGR3:
case VBLK_DGR4:
- list_add (&vb->list, &ldb->v_dgrp);
+ list_add(&vb->list, &ldb->v_dgrp);
break;
case VBLK_DSK3:
case VBLK_DSK4:
- list_add (&vb->list, &ldb->v_disk);
+ list_add(&vb->list, &ldb->v_disk);
break;
case VBLK_VOL5:
- list_add (&vb->list, &ldb->v_volu);
+ list_add(&vb->list, &ldb->v_volu);
break;
case VBLK_CMP3:
- list_add (&vb->list, &ldb->v_comp);
+ list_add(&vb->list, &ldb->v_comp);
break;
case VBLK_PRT3:
/* Sort by the partition's start sector. */
- list_for_each (item, &ldb->v_part) {
- struct vblk *v = list_entry (item, struct vblk, list);
+ list_for_each(item, &ldb->v_part) {
+ struct vblk *v = list_entry(item, struct vblk, list);
if ((v->vblk.part.disk_id == vb->vblk.part.disk_id) &&
(v->vblk.part.start > vb->vblk.part.start)) {
- list_add_tail (&vb->list, &v->list);
+ list_add_tail(&vb->list, &v->list);
return true;
}
}
- list_add_tail (&vb->list, &ldb->v_part);
+ list_add_tail(&vb->list, &ldb->v_part);
break;
}
return true;
@@ -1293,13 +1314,13 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)
* Return: 'true' Success, the VBLK was added to the list
* 'false' Error, a problem occurred
*/
-static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
+static bool ldm_frag_add(const u8 *data, int size, struct list_head *frags)
{
struct frag *f;
struct list_head *item;
int rec, num, group;

- BUG_ON (!data || !frags);
+ BUG_ON(!data || !frags);

if (size < 2 * VBLK_SIZE_HEAD) {
ldm_error("Value of size is to small.");
@@ -1310,7 +1331,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
rec = get_unaligned_be16(data + 0x0C);
num = get_unaligned_be16(data + 0x0E);
if ((num < 1) || (num > 4)) {
- ldm_error ("A VBLK claims to have %d parts.", num);
+ ldm_error("A VBLK claims to have %d parts.", num);
return false;
}
if (rec >= num) {
@@ -1318,13 +1339,13 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
return false;
}

- list_for_each (item, frags) {
- f = list_entry (item, struct frag, list);
+ list_for_each(item, frags) {
+ f = list_entry(item, struct frag, list);
if (f->group == group)
goto found;
}

- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
+ f = kmalloc(sizeof(*f) + size*num, GFP_KERNEL);
if (!f)
return false;

@@ -1340,7 +1361,7 @@ found:
return false;
}
if (f->map & (1 << rec)) {
- ldm_error ("Duplicate VBLK, part %d.", rec);
+ ldm_error("Duplicate VBLK, part %d.", rec);
f->map &= 0x7F; /* Mark the group as broken */
return false;
}
@@ -1361,14 +1382,14 @@ found:
*
* Return: none
*/
-static void ldm_frag_free (struct list_head *list)
+static void ldm_frag_free(struct list_head *list)
{
struct list_head *item, *tmp;

- BUG_ON (!list);
+ BUG_ON(!list);

- list_for_each_safe (item, tmp, list)
- kfree (list_entry (item, struct frag, list));
+ list_for_each_safe(item, tmp, list)
+ kfree(list_entry(item, struct frag, list));
}

/**
@@ -1382,23 +1403,23 @@ static void ldm_frag_free (struct list_head *list)
* Return: 'true' All the fragments we added successfully
* 'false' One or more of the fragments we invalid
*/
-static bool ldm_frag_commit (struct list_head *frags, struct ldmdb *ldb)
+static bool ldm_frag_commit(struct list_head *frags, struct ldmdb *ldb)
{
struct frag *f;
struct list_head *item;

- BUG_ON (!frags || !ldb);
+ BUG_ON(!frags || !ldb);

- list_for_each (item, frags) {
- f = list_entry (item, struct frag, list);
+ list_for_each(item, frags) {
+ f = list_entry(item, struct frag, list);

if (f->map != 0xFF) {
- ldm_error ("VBLK group %d is incomplete (0x%02x).",
+ ldm_error("VBLK group %d is incomplete (0x%02x).",
f->group, f->map);
return false;
}

- if (!ldm_ldmdb_add (f->data, f->num*ldb->vm.vblk_size, ldb))
+ if (!ldm_ldmdb_add(f->data, f->num*ldb->vm.vblk_size, ldb))
return false; /* Already logged */
}
return true;
@@ -1435,35 +1456,35 @@ static bool ldm_get_vblks(struct parsed_partitions *state, unsigned long base,
for (s = skip; s < finish; s++) { /* For each sector */
data = read_part_sector(state, base + OFF_VMDB + s, &sect);
if (!data) {
- ldm_crit ("Disk read failed.");
+ ldm_crit("Disk read failed.");
goto out;
}

for (v = 0; v < perbuf; v++, data+=size) { /* For each vblk */
if (MAGIC_VBLK != get_unaligned_be32(data)) {
- ldm_error ("Expected to find a VBLK.");
+ ldm_error("Expected to find a VBLK.");
goto out;
}

recs = get_unaligned_be16(data + 0x0E); /* Number of records */
if (recs == 1) {
- if (!ldm_ldmdb_add (data, size, ldb))
+ if (!ldm_ldmdb_add(data, size, ldb))
goto out; /* Already logged */
} else if (recs > 1) {
- if (!ldm_frag_add (data, size, &frags))
+ if (!ldm_frag_add(data, size, &frags))
goto out; /* Already logged */
}
/* else Record is not in use, ignore it. */
}
- put_dev_sector (sect);
+ put_dev_sector(sect);
data = NULL;
}

- result = ldm_frag_commit (&frags, ldb); /* Failures, already logged */
+ result = ldm_frag_commit(&frags, ldb); /* Failures, already logged */
out:
if (data)
- put_dev_sector (sect);
- ldm_frag_free (&frags);
+ put_dev_sector(sect);
+ ldm_frag_free(&frags);

return result;
}
@@ -1476,14 +1497,14 @@ out:
*
* Return: none
*/
-static void ldm_free_vblks (struct list_head *lh)
+static void ldm_free_vblks(struct list_head *lh)
{
struct list_head *item, *tmp;

- BUG_ON (!lh);
+ BUG_ON(!lh);

- list_for_each_safe (item, tmp, lh)
- kfree (list_entry (item, struct vblk, list));
+ list_for_each_safe(item, tmp, lh)
+ kfree(list_entry(item, struct vblk, list));
}


@@ -1516,7 +1537,7 @@ int ldm_partition(struct parsed_partitions *state)
if (!ldm_validate_partition_table(state))
return 0;

- ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
+ ldb = kmalloc(sizeof(*ldb), GFP_KERNEL);
if (!ldb)
return -1;

@@ -1533,31 +1554,31 @@ int ldm_partition(struct parsed_partitions *state)
goto out; /* Already logged */

/* Initialize vblk lists in ldmdb struct */
- INIT_LIST_HEAD (&ldb->v_dgrp);
- INIT_LIST_HEAD (&ldb->v_disk);
- INIT_LIST_HEAD (&ldb->v_volu);
- INIT_LIST_HEAD (&ldb->v_comp);
- INIT_LIST_HEAD (&ldb->v_part);
+ INIT_LIST_HEAD(&ldb->v_dgrp);
+ INIT_LIST_HEAD(&ldb->v_disk);
+ INIT_LIST_HEAD(&ldb->v_volu);
+ INIT_LIST_HEAD(&ldb->v_comp);
+ INIT_LIST_HEAD(&ldb->v_part);

if (!ldm_get_vblks(state, base, ldb)) {
- ldm_crit ("Failed to read the VBLKs from the database.");
+ ldm_crit("Failed to read the VBLKs from the database.");
goto cleanup;
}

/* Finally, create the data partition devices. */
if (ldm_create_data_partitions(state, ldb)) {
- ldm_debug ("Parsed LDM database successfully.");
+ ldm_debug("Parsed LDM database successfully.");
result = 1;
}
/* else Already logged */

cleanup:
- ldm_free_vblks (&ldb->v_dgrp);
- ldm_free_vblks (&ldb->v_disk);
- ldm_free_vblks (&ldb->v_volu);
- ldm_free_vblks (&ldb->v_comp);
- ldm_free_vblks (&ldb->v_part);
+ ldm_free_vblks(&ldb->v_dgrp);
+ ldm_free_vblks(&ldb->v_disk);
+ ldm_free_vblks(&ldb->v_volu);
+ ldm_free_vblks(&ldb->v_comp);
+ ldm_free_vblks(&ldb->v_part);
out:
- kfree (ldb);
+ kfree(ldb);
return result;
}
--
2.6.3

2015-12-24 12:31:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] Documentation-getdelays: Fine-tuning for two functions

From: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 13:23:34 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Fix a check for container file usage in main()
Apply a recommendation from "checkpatch.pl" in main()
Less function calls in usage()

Documentation/accounting/getdelays.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

--
2.6.3

2015-12-24 12:34:40

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] Documentation-getdelays: Fix a check for container file usage in main()

From: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 11:00:54 +0100

The close() function could be called by the main() function even if
the passed variable "cfd" was assigned a negative value.

* Corresponding implementation details could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Fix the affected condition check.

Signed-off-by: Markus Elfring <[email protected]>
---
Documentation/accounting/getdelays.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index f405780..6656c0c 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -383,7 +383,7 @@ int main(int argc, char *argv[])
id = get_family_id(nl_sd);
if (!id) {
fprintf(stderr, "Error getting family id, errno %d\n", errno);
- goto err;
+ goto close_socket;
}
PRINTF("family id %d\n", id);

@@ -394,13 +394,13 @@ int main(int argc, char *argv[])
PRINTF("Sent register cpumask, retval %d\n", rc);
if (rc < 0) {
fprintf(stderr, "error sending register cpumask\n");
- goto err;
+ goto close_socket;
}
}

if (tid && containerset) {
fprintf(stderr, "Select either -t or -C, not both\n");
- goto err;
+ goto close_socket;
}

/*
@@ -426,18 +426,18 @@ int main(int argc, char *argv[])
cfd = open(containerpath, O_RDONLY);
if (cfd < 0) {
perror("error opening container file");
- goto err;
+ goto close_socket;
}
rc = send_cmd(nl_sd, id, mypid, CGROUPSTATS_CMD_GET,
CGROUPSTATS_CMD_ATTR_FD, &cfd, sizeof(__u32));
if (rc < 0) {
perror("error sending cgroupstats command");
- goto err;
+ goto close_container;
}
}
if (!maskset && !tid && !containerset) {
usage();
- goto err;
+ goto check_container;
}

do {
@@ -536,11 +536,14 @@ done:
if (rc < 0)
err(rc, "error sending deregister cpumask\n");
}
-err:
+check_container:
+ if (cfd >= 0) {
+close_container:
+ close(cfd);
+ }
+close_socket:
close(nl_sd);
if (fd)
close(fd);
- if (cfd)
- close(cfd);
return 0;
}
--
2.6.3

2015-12-24 12:36:55

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()

From: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 11:05:32 +0100

The script "checkpatch.pl" pointed out that assignments should usually
not be performed within condition checks.
Thus move the assignment for the variable "nl_sd" to a separate statement.

Signed-off-by: Markus Elfring <[email protected]>
---
Documentation/accounting/getdelays.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index 6656c0c..9ca318d 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -375,7 +375,8 @@ int main(int argc, char *argv[])
}
}

- if ((nl_sd = create_nl_socket(NETLINK_GENERIC)) < 0)
+ nl_sd = create_nl_socket(NETLINK_GENERIC);
+ if (nl_sd < 0)
err(1, "error creating Netlink socket\n");


--
2.6.3

2015-12-24 12:38:13

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] Documentation-getdelays: Less function calls in usage()

From: Markus Elfring <[email protected]>
Date: Thu, 24 Dec 2015 13:10:19 +0100

A single call of the fprintf() function is sufficient for the desired
display of the usage information.

Signed-off-by: Markus Elfring <[email protected]>
---
Documentation/accounting/getdelays.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index 9ca318d..1ad3de8 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -74,12 +74,12 @@ char cpumask[100+6*MAX_CPUS];
static void usage(void)
{
fprintf(stderr, "getdelays [-dilv] [-w logfile] [-r bufsize] "
- "[-m cpumask] [-t tgid] [-p pid]\n");
- fprintf(stderr, " -d: print delayacct stats\n");
- fprintf(stderr, " -i: print IO accounting (works only with -p)\n");
- fprintf(stderr, " -l: listen forever\n");
- fprintf(stderr, " -v: debug on\n");
- fprintf(stderr, " -C: container path\n");
+ "[-m cpumask] [-t tgid] [-p pid]\n"
+ " -d: print delayacct stats\n"
+ " -i: print IO accounting (works only with -p)\n"
+ " -l: listen forever\n"
+ " -v: debug on\n"
+ " -C: container path\n");
}

/*
--
2.6.3

2015-12-24 14:22:18

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH 1/3] Documentation-getdelays: Fix a check for container file usage in main()

On Thu, 24 Dec 2015 13:34:20 +0100
SF Markus Elfring <[email protected]> wrote:

> The close() function could be called by the main() function even if
> the passed variable "cfd" was assigned a negative value.
>
> * Corresponding implementation details could be improved by adjustments
> for jump targets according to the Linux coding style convention.
>
> * Fix the affected condition check.

This seems more easily fixed by simply making the condition > 0.
Meanwhile, I'd really not add labels-inside-if-statements as an example
in the documentation tree.

Thanks,

jon

2015-12-24 14:22:59

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH 2/3] Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()

On Thu, 24 Dec 2015 13:36:48 +0100
SF Markus Elfring <[email protected]> wrote:

> The script "checkpatch.pl" pointed out that assignments should usually
> not be performed within condition checks.
> Thus move the assignment for the variable "nl_sd" to a separate statement.

Fine, applied to the docs tree.

jon

2015-12-24 14:23:41

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH 3/3] Documentation-getdelays: Less function calls in usage()

On Thu, 24 Dec 2015 13:38:01 +0100
SF Markus Elfring <[email protected]> wrote:

> A single call of the fprintf() function is sufficient for the desired
> display of the usage information.

This seems like churn that doesn't actually fix anything.

jon

2015-12-24 17:55:11

by SF Markus Elfring

[permalink] [raw]
Subject: Re: Documentation-getdelays: Fix a check for container file usage in main()

>> The close() function could be called by the main() function even if
>> the passed variable "cfd" was assigned a negative value.
?
> This seems more easily fixed by simply making the condition > 0.

How do you think about the reuse of the error predicate "cfd != -1"
for the return value from a call of the function "open"?
http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/Documentation/accounting/getdelays.c?id=80c75a0f1d81922bf322c0634d1e1a15825a89e6#n425


> Meanwhile, I'd really not add labels-inside-if-statements as an example
> in the documentation tree.

How are the chances to improve the affected error detection
and corresponding exception handling?

Regards,
Markus

2015-12-24 19:40:52

by SF Markus Elfring

[permalink] [raw]
Subject: Re: Documentation-getdelays: Less function calls in usage()

>> A single call of the fprintf() function is sufficient for the desired
>> display of the usage information.
>
> This seems like churn that doesn't actually fix anything.

Will it matter occasionally to reduce the number of function calls
by combining several text fragments into the passing of one longer
string parameter?

Does a warning like "quoted string split across lines" need also
any further considerations for the Linux coding style specification?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/scripts/checkpatch.pl?id=80c75a0f1d81922bf322c0634d1e1a15825a89e6#n4837

Regards,
Markus

2015-12-25 10:36:28

by SF Markus Elfring

[permalink] [raw]
Subject: ACPI-fan: Another source code review around null pointer handling?

Hello,

I have looked at the source file for the ACPI fan driver once more.
I would appreciate if a specific implementation detail can be clarified there.

Static source code analysis can point out that functions like the following
share an approach for error detection and corresponding exception handling.
* acpi_fan_get_fif
* acpi_fan_get_fps
* fan_get_state_acpi4
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/acpi/fan.c?id=80c75a0f1d81922bf322c0634d1e1a15825a89e6#n107

Can it matter eventually to handle a detected null pointer differently from
further checks for an attribute like "obj->type" or "obj->package"?

Regards,
Markus

2015-12-25 16:00:49

by SF Markus Elfring

[permalink] [raw]
Subject: sata_mv: Another source code review around exception handling?

Hello,

I have looked at the source file for the Marvell SATA support driver once more.
I would appreciate if a specific implementation detail can be clarified there.

Static source code analysis can point out that functions like the following
are called by the mv_platform_probe() function.
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/ata/sata_mv.c?id=80c75a0f1d81922bf322c0634d1e1a15825a89e6#n4055

* ata_host_alloc_pinfo
http://lxr.free-electrons.com/source/drivers/ata/libata-core.c?v=4.3#L5768

* devm_kzalloc
http://lxr.free-electrons.com/source/include/linux/device.h?v=4.3#L645


The value "-ENOMEM" will be returned if one of these function calls failed.
Can it be that any system resources (like memory) are not appropriately
released if any calls of this sequence succeeded before the failure?


Is the use of the single jump label "err" also suspicious here?

Regards,
Markus

2015-12-25 18:49:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] gpio-ucb1400: Delete an unnecessary variable initialisation in ucb1400_gpio_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 25 Dec 2015 19:36:20 +0100

The variable "err" will eventually be set to an appropriate value
from a call of the gpiochip_add() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/gpio/gpio-ucb1400.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ucb1400.c b/drivers/gpio/gpio-ucb1400.c
index d502825..c963517 100644
--- a/drivers/gpio/gpio-ucb1400.c
+++ b/drivers/gpio/gpio-ucb1400.c
@@ -46,7 +46,7 @@ static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
static int ucb1400_gpio_probe(struct platform_device *dev)
{
struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
- int err = 0;
+ int err;

if (!(ucb && ucb->gpio_offset)) {
err = -EINVAL;
--
2.6.3

2015-12-26 06:35:20

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] i2c-core: One function call less in acpi_i2c_space_handler() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 07:30:35 +0100

The kfree() function was called in one case by the
acpi_i2c_space_handler() function during error handling
even if the passed variable "client" contained a null pointer.

Implementation details could be improved by the adjustment of jump targets.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/i2c/i2c-core.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7349b00..a24e06c 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -313,18 +313,18 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client) {
ret = AE_NO_MEMORY;
- goto err;
+ goto free_ares;
}

if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

sb = &ares->data.i2c_serial_bus;
if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

client->adapter = adapter;
@@ -405,9 +405,9 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
}

gsb->status = status;
-
- err:
+free_client:
kfree(client);
+free_ares:
ACPI_FREE(ares);
return ret;
}
--
2.6.3

2015-12-26 06:45:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] i2c-core: One function call less in acpi_i2c_space_handler() after error detection

[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Markus,

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on v4.4-rc6 next-20151223]

url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/i2c-core-One-function-call-less-in-acpi_i2c_space_handler-after-error-detection/20151226-143820
base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux i2c/for-next
config: x86_64-randconfig-x010-12251849 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

All errors (new ones prefixed by >>):

drivers/i2c/i2c-core.c: In function 'acpi_i2c_space_handler':
>> drivers/i2c/i2c-core.c:404:3: error: label 'err' used but not defined
goto err;
^

vim +/err +404 drivers/i2c/i2c-core.c

17f4a5c4 Wolfram Sang 2014-09-22 398 }
17f4a5c4 Wolfram Sang 2014-09-22 399 break;
17f4a5c4 Wolfram Sang 2014-09-22 400
17f4a5c4 Wolfram Sang 2014-09-22 401 default:
17f4a5c4 Wolfram Sang 2014-09-22 402 pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
17f4a5c4 Wolfram Sang 2014-09-22 403 ret = AE_BAD_PARAMETER;
17f4a5c4 Wolfram Sang 2014-09-22 @404 goto err;
17f4a5c4 Wolfram Sang 2014-09-22 405 }
17f4a5c4 Wolfram Sang 2014-09-22 406
17f4a5c4 Wolfram Sang 2014-09-22 407 gsb->status = status;

:::::: The code at line 404 was first introduced by commit
:::::: 17f4a5c47f28de9ea59182f48d07f8c44ee5dcc9 i2c: move acpi code back into the core

:::::: TO: Wolfram Sang <[email protected]>
:::::: CC: Wolfram Sang <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.75 kB)
.config.gz (24.51 kB)
Download all attachments

2015-12-26 07:08:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2] i2c-core: One function call less in acpi_i2c_space_handler() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 08:00:52 +0100

The kfree() function was called in one case by the
acpi_i2c_space_handler() function during error handling
even if the passed variable "client" contained a null pointer.

Implementation details could be improved by the adjustment of jump targets
according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/i2c/i2c-core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7349b00..9996531 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -313,18 +313,18 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client) {
ret = AE_NO_MEMORY;
- goto err;
+ goto free_ares;
}

if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

sb = &ares->data.i2c_serial_bus;
if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

client->adapter = adapter;
@@ -401,13 +401,13 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
default:
pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

gsb->status = status;
-
- err:
+free_client:
kfree(client);
+free_ares:
ACPI_FREE(ares);
return ret;
}
--
2.6.3

2015-12-26 07:49:09

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2] i2c-core: One function call less in acpi_i2c_space_handler() after error detection

> The kfree() function was called in one case by the
> acpi_i2c_space_handler() function during error handling
> even if the passed variable "client" contained a null pointer.

This is OK. kfree() is known to be NULL-tolerant and we rely on it in
various places to keep the code simpler.


Attachments:
(No filename) (289.00 B)
signature.asc (819.00 B)
Download all attachments

2015-12-26 08:52:21

by SF Markus Elfring

[permalink] [raw]
Subject: Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection

>> The kfree() function was called in one case by the
>> acpi_i2c_space_handler() function during error handling
>> even if the passed variable "client" contained a null pointer.
>
> This is OK. kfree() is known to be NULL-tolerant and we rely on it in
> various places to keep the code simpler.

I would appreciate if an unnecessary function call can be avoided here
so that the affected exception handling can become also a bit more efficient.

Regards,
Markus

2015-12-26 10:10:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 11:04:56 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
One function call less in ide_get_dev_handle() after error detection
Delete unnecessary null pointer checks in ide_get_dev_handle()
Move an assignment for one variable in ide_get_dev_handle()

drivers/ide/ide-acpi.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

--
2.6.3

2015-12-26 10:15:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] IDE-ACPI: One function call less in ide_get_dev_handle() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:01:36 +0100

The kfree() function was called in two cases by the
ide_get_dev_handle() function during error handling
even if the passed variable "dinfo" contained a null pointer.

* Let us return directly if a call of the function "ACPI_HANDLE"
or "acpi_get_object_info" failed.

* Delete the explicit initialisation for the variables "dinfo" and "ret"
at the beginning then.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/ide/ide-acpi.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index b694099..319b754 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -126,8 +126,8 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
u64 addr;
acpi_handle dev_handle;
acpi_status status;
- struct acpi_device_info *dinfo = NULL;
- int ret = -ENODEV;
+ struct acpi_device_info *dinfo;
+ int ret;

bus = pdev->bus->number;
devnum = PCI_SLOT(pdev->devfn);
@@ -140,13 +140,13 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
dev_handle = ACPI_HANDLE(dev);
if (!dev_handle) {
DEBPRINT("no acpi handle for device\n");
- goto err;
+ return -ENODEV;
}

status = acpi_get_object_info(dev_handle, &dinfo);
if (ACPI_FAILURE(status)) {
DEBPRINT("get_object_info for device failed\n");
- goto err;
+ return -ENODEV;
}
if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
dinfo->address == addr) {
@@ -157,13 +157,14 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
" address: %llu, should be %u\n",
dinfo ? (unsigned long long)dinfo->address : -1ULL,
(unsigned int)addr);
- goto err;
+ ret = -ENODEV;
+ goto free_info;
}

DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n",
devnum, func, (unsigned long long)addr, *handle);
ret = 0;
-err:
+free_info:
kfree(dinfo);
return ret;
}
--
2.6.3

2015-12-26 10:17:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] IDE-ACPI: Delete unnecessary null pointer checks in ide_get_dev_handle()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:33:48 +0100

The variable "dinfo" will contain an appropropriate pointer after a call
of the acpi_get_object_info() function succeeded.
Thus remove two safety checks.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/ide/ide-acpi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 319b754..b6b2111 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -148,14 +148,14 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
DEBPRINT("get_object_info for device failed\n");
return -ENODEV;
}
- if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
+ if ((dinfo->valid & ACPI_VALID_ADR) &&
dinfo->address == addr) {
*pcidevfn = addr;
*handle = dev_handle;
} else {
DEBPRINT("get_object_info for device has wrong "
" address: %llu, should be %u\n",
- dinfo ? (unsigned long long)dinfo->address : -1ULL,
+ (unsigned long long)dinfo->address,
(unsigned int)addr);
ret = -ENODEV;
goto free_info;
--
2.6.3

2015-12-26 10:20:26

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] IDE-ACPI: Move an assignment for one variable in ide_get_dev_handle()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 10:50:33 +0100

Move the assignment for the variable "addr" to the statement
where its value is used after previous function calls succeeded.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/ide/ide-acpi.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index b6b2111..c2de9f9 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -132,9 +132,6 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
bus = pdev->bus->number;
devnum = PCI_SLOT(pdev->devfn);
func = PCI_FUNC(pdev->devfn);
- /* ACPI _ADR encoding for PCI bus: */
- addr = (u64)(devnum << 16 | func);
-
DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func);

dev_handle = ACPI_HANDLE(dev);
@@ -148,6 +145,8 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
DEBPRINT("get_object_info for device failed\n");
return -ENODEV;
}
+ /* ACPI _ADR encoding for PCI bus: */
+ addr = (u64)(devnum << 16 | func);
if ((dinfo->valid & ACPI_VALID_ADR) &&
dinfo->address == addr) {
*pcidevfn = addr;
--
2.6.3

2015-12-26 13:04:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 13:53:15 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "ret" does not need to be checked once more
after it was determined that a function call failed.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
index c2babe5..391eefa 100644
--- a/drivers/iio/adc/qcom-spmi-vadc.c
+++ b/drivers/iio/adc/qcom-spmi-vadc.c
@@ -424,7 +424,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
prop = vadc_get_channel(vadc, VADC_REF_1250MV);
ret = vadc_do_conversion(vadc, prop, &read_1);
if (ret)
- goto err;
+ goto report_failure;

/* Try with buffered 625mV channel first */
prop = vadc_get_channel(vadc, VADC_SPARE1);
@@ -433,11 +433,11 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)

ret = vadc_do_conversion(vadc, prop, &read_2);
if (ret)
- goto err;
+ goto report_failure;

if (read_1 == read_2) {
ret = -EINVAL;
- goto err;
+ goto report_failure;
}

vadc->graph[VADC_CALIB_ABSOLUTE].dy = read_1 - read_2;
@@ -447,23 +447,24 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
prop = vadc_get_channel(vadc, VADC_VDD_VADC);
ret = vadc_do_conversion(vadc, prop, &read_1);
if (ret)
- goto err;
+ goto report_failure;

prop = vadc_get_channel(vadc, VADC_GND_REF);
ret = vadc_do_conversion(vadc, prop, &read_2);
if (ret)
- goto err;
+ goto report_failure;

if (read_1 == read_2) {
ret = -EINVAL;
- goto err;
+ goto report_failure;
}

vadc->graph[VADC_CALIB_RATIOMETRIC].dy = read_1 - read_2;
vadc->graph[VADC_CALIB_RATIOMETRIC].gnd = read_2;
-err:
- if (ret)
+ if (ret) {
+report_failure:
dev_err(vadc->dev, "measure reference points failed\n");
+ }

return ret;
}
--
2.6.3

2015-12-26 18:13:15

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function


IDE is in deep freeze maintainence mode.

Therefore patches that perform simplications and cleanups will
not be accepted.

Thanks.

2015-12-26 18:39:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/6] InfiniBand-ocrdma: Fine-tuning for some function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 19:30:54 +0100

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (6):
One variable and jump label less in ocrdma_alloc_ucontext_pd()
Delete unnecessary variable initialisations in 11 functions
Returning only value constants in ocrdma_qp_state_change()
Return a value from a function call in _ocrdma_modify_qp() directly
Returning only value constants in ocrdma_resize_cq()
Delete an unnecessary variable in ocrdma_dealloc_pd()

drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +-
drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 7 +++---
drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 +--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 39 +++++++++++------------------
4 files changed, 20 insertions(+), 32 deletions(-)

--
2.6.3

2015-12-26 18:42:01

by Wolfram Sang

[permalink] [raw]
Subject: Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection

On Sat, Dec 26, 2015 at 09:52:11AM +0100, SF Markus Elfring wrote:
> >> The kfree() function was called in one case by the
> >> acpi_i2c_space_handler() function during error handling
> >> even if the passed variable "client" contained a null pointer.
> >
> > This is OK. kfree() is known to be NULL-tolerant and we rely on it in
> > various places to keep the code simpler.
>
> I would appreciate if an unnecessary function call can be avoided here
> so that the affected exception handling can become also a bit more efficient.

Simpler code is easier to maintain. See your patch, you didn't get it
correctly at your first try. Also, this is not a hot path, so I see
it as a micro-optimization also adding complexity. I don't favor that.


Attachments:
(No filename) (743.00 B)
signature.asc (819.00 B)
Download all attachments

2015-12-26 18:44:12

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/6] InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 17:16:00 +0100

This issue was detected by using the Coccinelle software.

* Let us return directly if a call of the _ocrdma_alloc_pd()
function failed.

* Delete the jump label "err" and the local variable "status" then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 583001b..374c839 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -483,19 +483,15 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,
struct ocrdma_ucontext *uctx,
struct ib_udata *udata)
{
- int status = 0;
-
uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);
if (IS_ERR(uctx->cntxt_pd)) {
- status = PTR_ERR(uctx->cntxt_pd);
uctx->cntxt_pd = NULL;
- goto err;
+ return PTR_ERR(uctx->cntxt_pd);
}

uctx->cntxt_pd->uctx = uctx;
uctx->cntxt_pd->ibpd.device = &dev->ibdev;
-err:
- return status;
+ return 0;
}

static int ocrdma_dealloc_ucontext_pd(struct ocrdma_ucontext *uctx)
--
2.6.3

2015-12-26 18:45:40

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/6] InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:18:18 +0100

The variable "status" will be set to an appropriate value a bit later.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_ah.c | 2 +-
drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 4 ++--
drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 4 ++--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 12 ++++++------
4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_ah.c b/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
index 9820074..98c0abd 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
@@ -59,7 +59,7 @@ static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
struct ib_ah_attr *attr, union ib_gid *sgid,
int pdid, bool *isvlan, u16 vlan_tag)
{
- int status = 0;
+ int status;
struct ocrdma_eth_vlan eth;
struct ocrdma_grh grh;
int eth_sz;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 30f67be..6647aa6 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -1089,7 +1089,7 @@ mbx_err:
static int ocrdma_nonemb_mbx_cmd(struct ocrdma_dev *dev, struct ocrdma_mqe *mqe,
void *payload_va)
{
- int status = 0;
+ int status;
struct ocrdma_mbx_rsp *rsp = payload_va;

if ((mqe->hdr.spcl_sge_cnt_emb & OCRDMA_MQE_HDR_EMB_MASK) >>
@@ -2842,7 +2842,7 @@ int ocrdma_mbx_destroy_srq(struct ocrdma_dev *dev, struct ocrdma_srq *srq)
static int ocrdma_mbx_get_dcbx_config(struct ocrdma_dev *dev, u32 ptype,
struct ocrdma_dcbx_cfg *dcbxcfg)
{
- int status = 0;
+ int status;
dma_addr_t pa;
struct ocrdma_mqe cmd;

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_stats.c b/drivers/infiniband/hw/ocrdma/ocrdma_stats.c
index 86c303a..119baa3 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_stats.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_stats.c
@@ -608,7 +608,7 @@ static char *ocrdma_driver_dbg_stats(struct ocrdma_dev *dev)
static void ocrdma_update_stats(struct ocrdma_dev *dev)
{
ulong now = jiffies, secs;
- int status = 0;
+ int status;
struct ocrdma_rdma_stats_resp *rdma_stats =
(struct ocrdma_rdma_stats_resp *)dev->stats_mem.va;
struct ocrdma_rsrc_stats *rsrc_stats = &rdma_stats->act_rsrc_stats;
@@ -639,7 +639,7 @@ static ssize_t ocrdma_dbgfs_ops_write(struct file *filp,
{
char tmp_str[32];
long reset;
- int status = 0;
+ int status;
struct ocrdma_stats *pstats = filp->private_data;
struct ocrdma_dev *dev = pstats->dev;

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 374c839..aba1b5a 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -419,7 +419,7 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
struct ib_udata *udata)
{
struct ocrdma_pd *pd = NULL;
- int status = 0;
+ int status;

pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (!pd)
@@ -468,7 +468,7 @@ static inline int is_ucontext_pd(struct ocrdma_ucontext *uctx,
static int _ocrdma_dealloc_pd(struct ocrdma_dev *dev,
struct ocrdma_pd *pd)
{
- int status = 0;
+ int status;

if (dev->pd_mgr->pd_prealloc_valid)
status = ocrdma_put_pd_num(dev, pd->id, pd->dpp_enabled);
@@ -592,7 +592,7 @@ map_err:

int ocrdma_dealloc_ucontext(struct ib_ucontext *ibctx)
{
- int status = 0;
+ int status;
struct ocrdma_mm *mm, *tmp;
struct ocrdma_ucontext *uctx = get_ocrdma_ucontext(ibctx);
struct ocrdma_dev *dev = get_ocrdma_dev(ibctx->device);
@@ -619,7 +619,7 @@ int ocrdma_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
unsigned long vm_page = vma->vm_pgoff << PAGE_SHIFT;
u64 unmapped_db = (u64) dev->nic_info.unmapped_db;
unsigned long len = (vma->vm_end - vma->vm_start);
- int status = 0;
+ int status;
bool found;

if (vma->vm_start & (PAGE_SIZE - 1))
@@ -1282,7 +1282,7 @@ static int ocrdma_copy_qp_uresp(struct ocrdma_qp *qp,
struct ib_udata *udata, int dpp_offset,
int dpp_credit_lmt, int srq)
{
- int status = 0;
+ int status;
u64 usr_db;
struct ocrdma_create_qp_uresp uresp;
struct ocrdma_pd *pd = qp->pd;
@@ -1946,7 +1946,7 @@ int ocrdma_modify_srq(struct ib_srq *ibsrq,
enum ib_srq_attr_mask srq_attr_mask,
struct ib_udata *udata)
{
- int status = 0;
+ int status;
struct ocrdma_srq *srq;

srq = get_ocrdma_srq(ibsrq);
--
2.6.3

2015-12-26 18:47:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:28:35 +0100

Return zero at the end without using the local variable "status".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 6647aa6..9a2b153 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -2110,7 +2110,6 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state,
enum ib_qp_state *old_ib_state)
{
unsigned long flags;
- int status = 0;
enum ocrdma_qp_state new_state;
new_state = get_ocrdma_qp_state(new_ib_state);

@@ -2135,7 +2134,7 @@ int ocrdma_qp_state_change(struct ocrdma_qp *qp, enum ib_qp_state new_ib_state,
qp->state = new_state;

spin_unlock_irqrestore(&qp->q_lock, flags);
- return status;
+ return 0;
}

static u32 ocrdma_set_create_qp_mbx_access_flags(struct ocrdma_qp *qp)
--
2.6.3

2015-12-26 18:49:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/6] InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:40:43 +0100

Return the value from a call of the ocrdma_mbx_modify_qp() function
without using an extra assignment for the local variable "status".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index aba1b5a..2de39d3 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -1491,9 +1491,7 @@ int _ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
*/
if (status < 0)
return status;
- status = ocrdma_mbx_modify_qp(dev, qp, attr, attr_mask);
-
- return status;
+ return ocrdma_mbx_modify_qp(dev, qp, attr, attr_mask);
}

int ocrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
--
2.6.3

2015-12-26 18:50:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:54:47 +0100

Return constant integer values without storing them in the local
variable "status".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 2de39d3..7bedf44 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -1120,15 +1120,12 @@ ctx_err:
int ocrdma_resize_cq(struct ib_cq *ibcq, int new_cnt,
struct ib_udata *udata)
{
- int status = 0;
struct ocrdma_cq *cq = get_ocrdma_cq(ibcq);

- if (new_cnt < 1 || new_cnt > cq->max_hw_cqe) {
- status = -EINVAL;
- return status;
- }
+ if (new_cnt < 1 || new_cnt > cq->max_hw_cqe)
+ return -EINVAL;
ibcq->cqe = new_cnt;
- return status;
+ return 0;
}

static void ocrdma_flush_cq(struct ocrdma_cq *cq)
--
2.6.3

2015-12-26 18:51:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/6] InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 19:09:23 +0100

1. Return zero in one case directly.

2. Return the value from a call of the _ocrdma_dealloc_pd() function
without using an extra assignment for the local variable.

3. Remove the variable "status" in this function then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 7bedf44..0f79a01 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -750,7 +750,6 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)
struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
struct ocrdma_ucontext *uctx = NULL;
- int status = 0;
u64 usr_db;

uctx = pd->uctx;
@@ -764,11 +763,10 @@ int ocrdma_dealloc_pd(struct ib_pd *ibpd)

if (is_ucontext_pd(uctx, pd)) {
ocrdma_release_ucontext_pd(uctx);
- return status;
+ return 0;
}
}
- status = _ocrdma_dealloc_pd(dev, pd);
- return status;
+ return _ocrdma_dealloc_pd(dev, pd);
}

static int ocrdma_alloc_lkey(struct ocrdma_dev *dev, struct ocrdma_mr *mr,
--
2.6.3

2015-12-26 19:30:39

by SF Markus Elfring

[permalink] [raw]
Subject: Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection

>> I would appreciate if an unnecessary function call can be avoided here
>> so that the affected exception handling can become also a bit more efficient.
>
> Simpler code is easier to maintain.

There are different opinions available around the desired simplicity.


> See your patch, you didn't get it correctly at your first try.

I wonder myself about the circumstances on how my incomplete update suggestion
did happen.


> Also, this is not a hot path,

I'm curious if approaches around better exception handling can eventually become
a "hot topic".


> so I see it as a micro-optimization

I can agree to this view for this function implementation.


> also adding complexity.

There are the usual software development trade-offs.


> I don't favor that.

Thanks for your constructive feedback.

Is an identifier like "free_client" a bit nicer (according to the Linux coding
style recommendations) than the short jump label "err" in the discussed use case?

Regards,
Markus

2015-12-26 19:42:58

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/6] InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()

[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Markus,

[auto build test WARNING on v4.4-rc6]
[also build test WARNING on next-20151223]

url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/InfiniBand-ocrdma-Fine-tuning-for-some-function-implementations/20151227-025304


coccinelle warnings: (new ones prefixed by >>)

>> drivers/infiniband/hw/ocrdma/ocrdma_verbs.c:489:9-16: ERROR: PTR_ERR applied after initialization to constant on line 488

vim +489 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c

482 static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,
483 struct ocrdma_ucontext *uctx,
484 struct ib_udata *udata)
485 {
486 uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);
487 if (IS_ERR(uctx->cntxt_pd)) {
> 488 uctx->cntxt_pd = NULL;
> 489 return PTR_ERR(uctx->cntxt_pd);
490 }
491
492 uctx->cntxt_pd->uctx = uctx;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

2015-12-26 21:29:10

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 1/6] InfiniBand-ocrdma: One jump label less in ocrdma_alloc_ucontext_pd()

From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 22:18:38 +0100

This issue was detected by using the Coccinelle software.

* Let us return directly if a call of the _ocrdma_alloc_pd()
function failed.

* Reduce the scope for the local variable "status" to one case
of an if statement.

* Delete the jump label "err" then.

* Return zero as a constant at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 583001b..7f10cc47 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -483,19 +483,16 @@ static int ocrdma_alloc_ucontext_pd(struct ocrdma_dev *dev,
struct ocrdma_ucontext *uctx,
struct ib_udata *udata)
{
- int status = 0;
-
uctx->cntxt_pd = _ocrdma_alloc_pd(dev, uctx, udata);
if (IS_ERR(uctx->cntxt_pd)) {
- status = PTR_ERR(uctx->cntxt_pd);
+ int status = PTR_ERR(uctx->cntxt_pd);
uctx->cntxt_pd = NULL;
- goto err;
+ return status;
}

uctx->cntxt_pd->uctx = uctx;
uctx->cntxt_pd->ibpd.device = &dev->ibdev;
-err:
- return status;
+ return 0;
}

static int ocrdma_dealloc_ucontext_pd(struct ocrdma_ucontext *uctx)
--
2.6.3

2015-12-26 23:43:26

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function

On Sat, 2015-12-26 at 13:12 -0500, David Miller wrote:
> IDE is in deep freeze maintainence mode.
>
> Therefore patches that perform simplications and cleanups will
> not be accepted.

Maybe there should be something like a README
in drivers/ide that says that.

Maybe the MAINTAINERS entry for "IDE SUBSYSTEM"
should be something like:

S: Frozen - critical fixes only

2015-12-27 06:08:53

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function



On Sat, 26 Dec 2015, Joe Perches wrote:

> On Sat, 2015-12-26 at 13:12 -0500, David Miller wrote:
> > IDE is in deep freeze maintainence mode.
> >
> > Therefore patches that perform simplications and cleanups will
> > not be accepted.
>
> Maybe there should be something like a README
> in drivers/ide that says that.
>
> Maybe the MAINTAINERS entry for "IDE SUBSYSTEM"
> should be something like:
>
> S: Frozen - critical fixes only

This could be a good idea. Sometimes I hold off on sending patches for
things becuse I have the impression that the subsystem doesn't want minor
fixes, but I could be wrong, and if one could have a deterministic way to
know, it could be better for everyone.

julia

2015-12-27 12:36:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations

From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations

I suggest to return directly instead of using the jump label "err"
in two functions (which are working without clean-up there).

Markus Elfring (2):
One jump label less in iser_reg_sig_mr()
One jump label less in isert_reg_sig_mr()

drivers/infiniband/ulp/iser/iser_memory.c | 5 ++---
drivers/infiniband/ulp/isert/ib_isert.c | 7 +++----
2 files changed, 5 insertions(+), 7 deletions(-)

--
2.6.3

2015-12-27 12:40:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] InfiniBand-iSER: One jump label less in iser_reg_sig_mr()

From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 11:41:42 +0100

This issue was detected by using the Coccinelle software.

1. Let us return directly if a call of the iser_set_sig_attrs()
function failed.

2. Delete the jump label "err" then.

3. Return zero as a constant at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/ulp/iser/iser_memory.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c
index ea765fb..14e08b3 100644
--- a/drivers/infiniband/ulp/iser/iser_memory.c
+++ b/drivers/infiniband/ulp/iser/iser_memory.c
@@ -443,7 +443,7 @@ iser_reg_sig_mr(struct iscsi_iser_task *iser_task,
memset(sig_attrs, 0, sizeof(*sig_attrs));
ret = iser_set_sig_attrs(iser_task->sc, sig_attrs);
if (ret)
- goto err;
+ return ret;

iser_set_prot_checks(iser_task->sc, &sig_attrs->check_mask);

@@ -475,8 +475,7 @@ iser_reg_sig_mr(struct iscsi_iser_task *iser_task,
iser_dbg("lkey=0x%x rkey=0x%x addr=0x%llx length=%u\n",
sig_reg->sge.lkey, sig_reg->rkey, sig_reg->sge.addr,
sig_reg->sge.length);
-err:
- return ret;
+ return 0;
}

static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task,
--
2.6.3

2015-12-27 12:42:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] InfiniBand-iSER-target: One jump label less in isert_reg_sig_mr()

From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 12:54:52 +0100

This issue was detected by using the Coccinelle software.

1. Let us return directly if a call of the function "isert_set_sig_attrs"
or "ib_post_send" failed.

2. Delete the jump label "err" then.

3. Return zero as a constant at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/infiniband/ulp/isert/ib_isert.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 8a51c3b..9b22db0 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -2660,7 +2660,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn,
memset(&sig_attrs, 0, sizeof(sig_attrs));
ret = isert_set_sig_attrs(se_cmd, &sig_attrs);
if (ret)
- goto err;
+ return ret;

sig_attrs.check_mask = isert_set_prot_checks(se_cmd->prot_checks);

@@ -2688,7 +2688,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn,
ret = ib_post_send(isert_conn->qp, wr, &bad_wr);
if (ret) {
isert_err("fast registration failed, ret:%d\n", ret);
- goto err;
+ return ret;
}
fr_desc->ind &= ~ISERT_SIG_KEY_VALID;

@@ -2706,8 +2706,7 @@ isert_reg_sig_mr(struct isert_conn *isert_conn,
isert_dbg("sig_sge: addr: 0x%llx length: %u lkey: %x\n",
rdma_wr->ib_sg[SIG].addr, rdma_wr->ib_sg[SIG].length,
rdma_wr->ib_sg[SIG].lkey);
-err:
- return ret;
+ return 0;
}

static int
--
2.6.3

2015-12-27 12:43:34

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations

On Sun, Dec 27, 2015 at 01:36:30PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 27 Dec 2015 13:12:10 +0100
> Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
Just a note for the future submissions (no need to respin), we are using
different subject line: InfiniBand-iSER: --> IB/iser:

>
> I suggest to return directly instead of using the jump label "err"
> in two functions (which are working without clean-up there).
>
> Markus Elfring (2):
> One jump label less in iser_reg_sig_mr()
> One jump label less in isert_reg_sig_mr()
>
> drivers/infiniband/ulp/iser/iser_memory.c | 5 ++---
> drivers/infiniband/ulp/isert/ib_isert.c | 7 +++----
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-12-27 12:52:15

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations

On Sun, Dec 27, 2015 at 01:36:30PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 27 Dec 2015 13:12:10 +0100
> Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
>
> I suggest to return directly instead of using the jump label "err"
> in two functions (which are working without clean-up there).
>
> Markus Elfring (2):
> One jump label less in iser_reg_sig_mr()
> One jump label less in isert_reg_sig_mr()
Looks good,
Reviewed-by: Leon Romanovsky <[email protected]>

>
> drivers/infiniband/ulp/iser/iser_memory.c | 5 ++---
> drivers/infiniband/ulp/isert/ib_isert.c | 7 +++----
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2015-12-27 15:26:30

by Sagi Grimberg

[permalink] [raw]
Subject: Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations

Along with Leon's prefix comment:

Acked-by: Sagi Grimberg <[email protected]>

2015-12-27 17:33:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] si2165: Refactoring for si2165_writereg_mask8()

From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 18:23:57 +0100

This issue was detected by using the Coccinelle software.

1. Let us return directly if a call of the si2165_readreg8()
function failed.

2. Reduce the scope for the local variables "ret" and "tmp" to one branch
of an if statement.

3. Delete the jump label "err" then.

4. Return the value from a call of the si2165_writereg8() function
without using an extra assignment for the variable "ret" at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/dvb-frontends/si2165.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 2b93241..e8518ae 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -225,22 +225,18 @@ static int si2165_writereg32(struct si2165_state *state, const u16 reg, u32 val)
static int si2165_writereg_mask8(struct si2165_state *state, const u16 reg,
u8 val, u8 mask)
{
- int ret;
- u8 tmp;
-
if (mask != 0xff) {
- ret = si2165_readreg8(state, reg, &tmp);
+ u8 tmp;
+ int ret = si2165_readreg8(state, reg, &tmp);
+
if (ret < 0)
- goto err;
+ return ret;

val &= mask;
tmp &= ~mask;
val |= tmp;
}
-
- ret = si2165_writereg8(state, reg, val);
-err:
- return ret;
+ return si2165_writereg8(state, reg, val);
}

#define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
--
2.6.3

2015-12-27 21:23:08

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] bttv: Returning only value constants in two functions

From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 22:02:21 +0100

Return constant integer values without storing them in the local
variable "err" or "rc".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/pci/bt8xx/bttv-driver.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 9400e99..cd7d6ef 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -1726,22 +1726,15 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id id)
struct bttv_fh *fh = priv;
struct bttv *btv = fh->btv;
unsigned int i;
- int err = 0;

for (i = 0; i < BTTV_TVNORMS; i++)
if (id & bttv_tvnorms[i].v4l2_id)
break;
- if (i == BTTV_TVNORMS) {
- err = -EINVAL;
- goto err;
- }
-
+ if (i == BTTV_TVNORMS)
+ return -EINVAL;
btv->std = id;
set_tvnorm(btv, i);
-
-err:
-
- return err;
+ return 0;
}

static int bttv_g_std(struct file *file, void *priv, v4l2_std_id *id)
@@ -1770,12 +1763,9 @@ static int bttv_enum_input(struct file *file, void *priv,
{
struct bttv_fh *fh = priv;
struct bttv *btv = fh->btv;
- int rc = 0;

- if (i->index >= bttv_tvcards[btv->c.type].video_inputs) {
- rc = -EINVAL;
- goto err;
- }
+ if (i->index >= bttv_tvcards[btv->c.type].video_inputs)
+ return -EINVAL;

i->type = V4L2_INPUT_TYPE_CAMERA;
i->audioset = 0;
@@ -1799,10 +1789,7 @@ static int bttv_enum_input(struct file *file, void *priv,
}

i->std = BTTV_NORMS;
-
-err:
-
- return rc;
+ return 0;
}

static int bttv_g_input(struct file *file, void *priv, unsigned int *i)
--
2.6.3

2015-12-28 09:15:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 10:10:34 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "ret" will not be checked once more
after it was determined that a function call failed.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/m88rs6000t.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/media/tuners/m88rs6000t.c b/drivers/media/tuners/m88rs6000t.c
index 504bfbc..b45594e 100644
--- a/drivers/media/tuners/m88rs6000t.c
+++ b/drivers/media/tuners/m88rs6000t.c
@@ -510,27 +510,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)

ret = regmap_read(dev->regmap, 0x5A, &val);
if (ret)
- goto err;
+ goto report_failure;
RF_GC = val & 0x0f;

ret = regmap_read(dev->regmap, 0x5F, &val);
if (ret)
- goto err;
+ goto report_failure;
IF_GC = val & 0x0f;

ret = regmap_read(dev->regmap, 0x3F, &val);
if (ret)
- goto err;
+ goto report_failure;
TIA_GC = (val >> 4) & 0x07;

ret = regmap_read(dev->regmap, 0x77, &val);
if (ret)
- goto err;
+ goto report_failure;
BB_GC = (val >> 4) & 0x0f;

ret = regmap_read(dev->regmap, 0x76, &val);
if (ret)
- goto err;
+ goto report_failure;
PGA2_GC = val & 0x3f;
PGA2_cri = PGA2_GC >> 2;
PGA2_crf = PGA2_GC & 0x03;
@@ -562,9 +562,11 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
/* scale value to 0x0000-0xffff */
gain = clamp_val(gain, 1000U, 10500U);
*strength = (10500 - gain) * 0xffff / (10500 - 1000);
-err:
- if (ret)
+
+ if (ret) {
+report_failure:
dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ }
return ret;
}

--
2.6.3

2015-12-28 09:20:24

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH] [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection

On Mon, 28 Dec 2015, SF Markus Elfring wrote:

> From: Markus Elfring <[email protected]>
> Date: Mon, 28 Dec 2015 10:10:34 +0100
>
> This issue was detected by using the Coccinelle software.
>
> Move the jump label directly before the desired log statement
> so that the variable "ret" will not be checked once more
> after it was determined that a function call failed.

Why not avoid both unnecessary ifs and the enormous ugliness of a label
inside an if by making two returns: a return 0 for success and a dev_dbg
and return ret for failure?

julia


> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/tuners/m88rs6000t.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/tuners/m88rs6000t.c b/drivers/media/tuners/m88rs6000t.c
> index 504bfbc..b45594e 100644
> --- a/drivers/media/tuners/m88rs6000t.c
> +++ b/drivers/media/tuners/m88rs6000t.c
> @@ -510,27 +510,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
>
> ret = regmap_read(dev->regmap, 0x5A, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> RF_GC = val & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x5F, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> IF_GC = val & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x3F, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> TIA_GC = (val >> 4) & 0x07;
>
> ret = regmap_read(dev->regmap, 0x77, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> BB_GC = (val >> 4) & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x76, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> PGA2_GC = val & 0x3f;
> PGA2_cri = PGA2_GC >> 2;
> PGA2_crf = PGA2_GC & 0x03;
> @@ -562,9 +562,11 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
> /* scale value to 0x0000-0xffff */
> gain = clamp_val(gain, 1000U, 10500U);
> *strength = (10500 - gain) * 0xffff / (10500 - 1000);
> -err:
> - if (ret)
> +
> + if (ret) {
> +report_failure:
> dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + }
> return ret;
> }
>
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-12-28 10:30:57

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection

>> Move the jump label directly before the desired log statement
>> so that the variable "ret" will not be checked once more
>> after it was determined that a function call failed.
>
> Why not avoid both unnecessary ifs

I would find such a fine-tuning also nice in principle at more source code places.


> and the enormous ugliness of a label inside an if by making two returns:
> a return 0 for success and a dev_dbg and return ret for failure?

How should your suggestion finally work when the desired execution success
can be determined for such functions only after several other calls succeeded?

Is consistent checking of failure predicates usually required?

Regards,
Markus

2015-12-28 10:36:30

by Julia Lawall

[permalink] [raw]
Subject: Re: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection



On Mon, 28 Dec 2015, SF Markus Elfring wrote:

> >> Move the jump label directly before the desired log statement
> >> so that the variable "ret" will not be checked once more
> >> after it was determined that a function call failed.
> >
> > Why not avoid both unnecessary ifs
>
> I would find such a fine-tuning also nice in principle at more source code places.
>
>
> > and the enormous ugliness of a label inside an if by making two returns:
> > a return 0 for success and a dev_dbg and return ret for failure?
>
> How should your suggestion finally work when the desired execution success
> can be determined for such functions only after several other calls succeeded?

Not idea what this means, but immediate return 0 followed by various code
for reacting to an error is very common, so it looks like it should be
possible here.

julia

2015-12-28 14:36:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] [media] m88rs6000t: Fine-tuning for some function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:32:20 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Better exception handling in five functions
Refactoring for m88rs6000t_sleep()

drivers/media/tuners/m88rs6000t.c | 165 +++++++++++++++++++-------------------
1 file changed, 83 insertions(+), 82 deletions(-)

--
2.6.3

2015-12-28 14:39:12

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:10:30 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "ret" will not be checked once more
after a function call.
Use the identifier "report_failure" instead of "err".

Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++-------------------
1 file changed, 78 insertions(+), 76 deletions(-)

diff --git a/drivers/media/tuners/m88rs6000t.c b/drivers/media/tuners/m88rs6000t.c
index 504bfbc..7e59a9f 100644
--- a/drivers/media/tuners/m88rs6000t.c
+++ b/drivers/media/tuners/m88rs6000t.c
@@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
/* select demod main mclk */
ret = regmap_read(dev->regmap, 0x15, &utmp);
if (ret)
- goto err;
+ goto report_failure;
reg15 = utmp;
if (c->symbol_rate > 45010000) {
reg11 = 0x0E;
@@ -106,7 +106,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)

ret = regmap_read(dev->regmap, 0x1D, &utmp);
if (ret)
- goto err;
+ goto report_failure;
reg1D = utmp;
reg1D &= ~0x03;
reg1D |= N - 1;
@@ -116,42 +116,42 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
/* program and recalibrate demod PLL */
ret = regmap_write(dev->regmap, 0x05, 0x40);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x11, 0x08);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x15, reg15);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x16, reg16);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x1D, reg1D);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x1E, reg1E);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x1F, reg1F);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x17, 0xc1);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x17, 0x81);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(5000, 50000);
ret = regmap_write(dev->regmap, 0x05, 0x00);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x11, reg11);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(5000, 50000);
-err:
- if (ret)
- dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ return 0;
+report_failure:
+ dev_dbg(&dev->client->dev, "failed=%d\n", ret);
return ret;
}

@@ -169,13 +169,13 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,

ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x31, 0x00);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x2c, 0x02);
if (ret)
- goto err;
+ goto report_failure;

if (tuner_freq_MHz >= 1550) {
ucLoDiv1 = 2;
@@ -227,105 +227,105 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
reg27 = (((ulNDiv1 >> 8) & 0x0F) + ucLomod1) & 0x7F;
ret = regmap_write(dev->regmap, 0x27, reg27);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv1 & 0xFF));
if (ret)
- goto err;
+ goto report_failure;
reg29 = (((ulNDiv2 >> 8) & 0x0F) + ucLomod2) & 0x7f;
ret = regmap_write(dev->regmap, 0x29, reg29);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x2a, (u8)(ulNDiv2 & 0xFF));
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x2F, 0xf5);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x30, 0x05);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x1f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x3f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x20);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x00);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x3e, 0x11);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x2f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x3f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x10);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x00);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(2000, 50000);

ret = regmap_read(dev->regmap, 0x42, &utmp);
if (ret)
- goto err;
+ goto report_failure;
reg42 = utmp;

ret = regmap_write(dev->regmap, 0x3e, 0x10);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x2f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x08, 0x3f);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x10);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x09, 0x00);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(2000, 50000);

ret = regmap_read(dev->regmap, 0x42, &utmp);
if (ret)
- goto err;
+ goto report_failure;
reg42buf = utmp;
if (reg42buf < reg42) {
ret = regmap_write(dev->regmap, 0x3e, 0x11);
if (ret)
- goto err;
+ goto report_failure;
}
usleep_range(5000, 50000);

ret = regmap_read(dev->regmap, 0x2d, &utmp);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x2d, utmp);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_read(dev->regmap, 0x2e, &utmp);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x2e, utmp);
if (ret)
- goto err;
+ goto report_failure;

ret = regmap_read(dev->regmap, 0x27, &utmp);
if (ret)
- goto err;
+ goto report_failure;
reg27 = utmp & 0x70;
ret = regmap_read(dev->regmap, 0x83, &utmp);
if (ret)
- goto err;
+ goto report_failure;
if (reg27 == (utmp & 0x70)) {
ucLoDiv = ucLoDiv1;
ulNDiv = ulNDiv1;
@@ -340,7 +340,7 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
refDiv = 18;
ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
if (ret)
- goto err;
+ goto report_failure;
ulNDiv = ((tuner_freq_MHz * ucLoDiv * 1000) * refDiv
/ fcry_KHz - 1024) / 2;
}
@@ -349,16 +349,16 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
+ ((ulNDiv >> 8) & 0x0F)) & 0xFF;
ret = regmap_write(dev->regmap, 0x27, reg27);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv & 0xFF));
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x29, 0x80);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x31, 0x03);
if (ret)
- goto err;
+ goto report_failure;

if (ucLoDiv == 3)
utmp = 0xCE;
@@ -366,15 +366,15 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
utmp = 0x8A;
ret = regmap_write(dev->regmap, 0x3b, utmp);
if (ret)
- goto err;
+ goto report_failure;

dev->frequency_khz = fcry_KHz * (ulNDiv * 2 + 1024) / refDiv / ucLoDiv;

dev_dbg(&dev->client->dev,
"actual tune frequency=%d\n", dev->frequency_khz);
-err:
- if (ret)
- dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ return 0;
+report_failure:
+ dev_dbg(&dev->client->dev, "failed=%d\n", ret);
return ret;
}

@@ -413,21 +413,23 @@ static int m88rs6000t_set_params(struct dvb_frontend *fe)
freq_MHz = (realFreq + 500) / 1000;
ret = m88rs6000t_set_pll_freq(dev, freq_MHz);
if (ret)
- goto err;
+ goto report_failure;
ret = m88rs6000t_set_bb(dev, c->symbol_rate / 1000, lpf_offset_KHz);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x00, 0x01);
if (ret)
- goto err;
+ goto report_failure;
ret = regmap_write(dev->regmap, 0x00, 0x00);
if (ret)
- goto err;
+ goto report_failure;
/* set demod mlck */
ret = m88rs6000t_set_demod_mclk(fe);
-err:
if (ret)
- dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ goto report_failure;
+ return 0;
+report_failure:
+ dev_dbg(&dev->client->dev, "failed=%d\n", ret);
return ret;
}

@@ -440,16 +442,16 @@ static int m88rs6000t_init(struct dvb_frontend *fe)

ret = regmap_update_bits(dev->regmap, 0x11, 0x08, 0x08);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(5000, 50000);
ret = regmap_update_bits(dev->regmap, 0x10, 0x01, 0x01);
if (ret)
- goto err;
+ goto report_failure;
usleep_range(10000, 50000);
ret = regmap_write(dev->regmap, 0x07, 0x7d);
-err:
- if (ret)
- dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ return 0;
+report_failure:
+ dev_dbg(&dev->client->dev, "failed=%d\n", ret);
return ret;
}

@@ -510,27 +512,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)

ret = regmap_read(dev->regmap, 0x5A, &val);
if (ret)
- goto err;
+ goto report_failure;
RF_GC = val & 0x0f;

ret = regmap_read(dev->regmap, 0x5F, &val);
if (ret)
- goto err;
+ goto report_failure;
IF_GC = val & 0x0f;

ret = regmap_read(dev->regmap, 0x3F, &val);
if (ret)
- goto err;
+ goto report_failure;
TIA_GC = (val >> 4) & 0x07;

ret = regmap_read(dev->regmap, 0x77, &val);
if (ret)
- goto err;
+ goto report_failure;
BB_GC = (val >> 4) & 0x0f;

ret = regmap_read(dev->regmap, 0x76, &val);
if (ret)
- goto err;
+ goto report_failure;
PGA2_GC = val & 0x3f;
PGA2_cri = PGA2_GC >> 2;
PGA2_crf = PGA2_GC & 0x03;
@@ -562,9 +564,9 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
/* scale value to 0x0000-0xffff */
gain = clamp_val(gain, 1000U, 10500U);
*strength = (10500 - gain) * 0xffff / (10500 - 1000);
-err:
- if (ret)
- dev_dbg(&dev->client->dev, "failed=%d\n", ret);
+ return 0;
+report_failure:
+ dev_dbg(&dev->client->dev, "failed=%d\n", ret);
return ret;
}

--
2.6.3

2015-12-28 14:42:50

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions



On Mon, 28 Dec 2015, SF Markus Elfring wrote:

> From: Markus Elfring <[email protected]>
> Date: Mon, 28 Dec 2015 15:10:30 +0100
>
> This issue was detected by using the Coccinelle software.
>
> Move the jump label directly before the desired log statement
> so that the variable "ret" will not be checked once more
> after a function call.

This commit message fits with the previous change.

It could be nice to put a blank line before the error handling code. See
what is done elsewhere in the file.

julia

>
> Suggested-by: Julia Lawall <[email protected]>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++-------------------
> 1 file changed, 78 insertions(+), 76 deletions(-)
>
> diff --git a/drivers/media/tuners/m88rs6000t.c b/drivers/media/tuners/m88rs6000t.c
> index 504bfbc..7e59a9f 100644
> --- a/drivers/media/tuners/m88rs6000t.c
> +++ b/drivers/media/tuners/m88rs6000t.c
> @@ -44,7 +44,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
> /* select demod main mclk */
> ret = regmap_read(dev->regmap, 0x15, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> reg15 = utmp;
> if (c->symbol_rate > 45010000) {
> reg11 = 0x0E;
> @@ -106,7 +106,7 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
>
> ret = regmap_read(dev->regmap, 0x1D, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> reg1D = utmp;
> reg1D &= ~0x03;
> reg1D |= N - 1;
> @@ -116,42 +116,42 @@ static int m88rs6000t_set_demod_mclk(struct dvb_frontend *fe)
> /* program and recalibrate demod PLL */
> ret = regmap_write(dev->regmap, 0x05, 0x40);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x11, 0x08);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x15, reg15);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x16, reg16);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x1D, reg1D);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x1E, reg1E);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x1F, reg1F);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x17, 0xc1);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x17, 0x81);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(5000, 50000);
> ret = regmap_write(dev->regmap, 0x05, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x11, reg11);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(5000, 50000);
> -err:
> - if (ret)
> - dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + return 0;
> +report_failure:
> + dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> return ret;
> }
>
> @@ -169,13 +169,13 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
>
> ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x31, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x2c, 0x02);
> if (ret)
> - goto err;
> + goto report_failure;
>
> if (tuner_freq_MHz >= 1550) {
> ucLoDiv1 = 2;
> @@ -227,105 +227,105 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
> reg27 = (((ulNDiv1 >> 8) & 0x0F) + ucLomod1) & 0x7F;
> ret = regmap_write(dev->regmap, 0x27, reg27);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv1 & 0xFF));
> if (ret)
> - goto err;
> + goto report_failure;
> reg29 = (((ulNDiv2 >> 8) & 0x0F) + ucLomod2) & 0x7f;
> ret = regmap_write(dev->regmap, 0x29, reg29);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x2a, (u8)(ulNDiv2 & 0xFF));
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x2F, 0xf5);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x30, 0x05);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x1f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x3f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x20);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x3e, 0x11);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x2f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x3f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x10);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(2000, 50000);
>
> ret = regmap_read(dev->regmap, 0x42, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> reg42 = utmp;
>
> ret = regmap_write(dev->regmap, 0x3e, 0x10);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x2f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x08, 0x3f);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x10);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x09, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(2000, 50000);
>
> ret = regmap_read(dev->regmap, 0x42, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> reg42buf = utmp;
> if (reg42buf < reg42) {
> ret = regmap_write(dev->regmap, 0x3e, 0x11);
> if (ret)
> - goto err;
> + goto report_failure;
> }
> usleep_range(5000, 50000);
>
> ret = regmap_read(dev->regmap, 0x2d, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x2d, utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_read(dev->regmap, 0x2e, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x2e, utmp);
> if (ret)
> - goto err;
> + goto report_failure;
>
> ret = regmap_read(dev->regmap, 0x27, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> reg27 = utmp & 0x70;
> ret = regmap_read(dev->regmap, 0x83, &utmp);
> if (ret)
> - goto err;
> + goto report_failure;
> if (reg27 == (utmp & 0x70)) {
> ucLoDiv = ucLoDiv1;
> ulNDiv = ulNDiv1;
> @@ -340,7 +340,7 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
> refDiv = 18;
> ret = regmap_write(dev->regmap, 0x36, (refDiv - 8));
> if (ret)
> - goto err;
> + goto report_failure;
> ulNDiv = ((tuner_freq_MHz * ucLoDiv * 1000) * refDiv
> / fcry_KHz - 1024) / 2;
> }
> @@ -349,16 +349,16 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
> + ((ulNDiv >> 8) & 0x0F)) & 0xFF;
> ret = regmap_write(dev->regmap, 0x27, reg27);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x28, (u8)(ulNDiv & 0xFF));
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x29, 0x80);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x31, 0x03);
> if (ret)
> - goto err;
> + goto report_failure;
>
> if (ucLoDiv == 3)
> utmp = 0xCE;
> @@ -366,15 +366,15 @@ static int m88rs6000t_set_pll_freq(struct m88rs6000t_dev *dev,
> utmp = 0x8A;
> ret = regmap_write(dev->regmap, 0x3b, utmp);
> if (ret)
> - goto err;
> + goto report_failure;
>
> dev->frequency_khz = fcry_KHz * (ulNDiv * 2 + 1024) / refDiv / ucLoDiv;
>
> dev_dbg(&dev->client->dev,
> "actual tune frequency=%d\n", dev->frequency_khz);
> -err:
> - if (ret)
> - dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + return 0;
> +report_failure:
> + dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> return ret;
> }
>
> @@ -413,21 +413,23 @@ static int m88rs6000t_set_params(struct dvb_frontend *fe)
> freq_MHz = (realFreq + 500) / 1000;
> ret = m88rs6000t_set_pll_freq(dev, freq_MHz);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = m88rs6000t_set_bb(dev, c->symbol_rate / 1000, lpf_offset_KHz);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x00, 0x01);
> if (ret)
> - goto err;
> + goto report_failure;
> ret = regmap_write(dev->regmap, 0x00, 0x00);
> if (ret)
> - goto err;
> + goto report_failure;
> /* set demod mlck */
> ret = m88rs6000t_set_demod_mclk(fe);
> -err:
> if (ret)
> - dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + goto report_failure;
> + return 0;
> +report_failure:
> + dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> return ret;
> }
>
> @@ -440,16 +442,16 @@ static int m88rs6000t_init(struct dvb_frontend *fe)
>
> ret = regmap_update_bits(dev->regmap, 0x11, 0x08, 0x08);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(5000, 50000);
> ret = regmap_update_bits(dev->regmap, 0x10, 0x01, 0x01);
> if (ret)
> - goto err;
> + goto report_failure;
> usleep_range(10000, 50000);
> ret = regmap_write(dev->regmap, 0x07, 0x7d);
> -err:
> - if (ret)
> - dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + return 0;
> +report_failure:
> + dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> return ret;
> }
>
> @@ -510,27 +512,27 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
>
> ret = regmap_read(dev->regmap, 0x5A, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> RF_GC = val & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x5F, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> IF_GC = val & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x3F, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> TIA_GC = (val >> 4) & 0x07;
>
> ret = regmap_read(dev->regmap, 0x77, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> BB_GC = (val >> 4) & 0x0f;
>
> ret = regmap_read(dev->regmap, 0x76, &val);
> if (ret)
> - goto err;
> + goto report_failure;
> PGA2_GC = val & 0x3f;
> PGA2_cri = PGA2_GC >> 2;
> PGA2_crf = PGA2_GC & 0x03;
> @@ -562,9 +564,9 @@ static int m88rs6000t_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
> /* scale value to 0x0000-0xffff */
> gain = clamp_val(gain, 1000U, 10500U);
> *strength = (10500 - gain) * 0xffff / (10500 - 1000);
> -err:
> - if (ret)
> - dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> + return 0;
> +report_failure:
> + dev_dbg(&dev->client->dev, "failed=%d\n", ret);
> return ret;
> }
>
> --
> 2.6.3
>
>

2015-12-28 14:43:04

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] [media] tuners: Refactoring for m88rs6000t_sleep()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:20:45 +0100

This issue was detected by using the Coccinelle software.

1. Let us return directly if a call of the regmap_write() function failed.

2. Delete the jump label "err" then.

3. Return zero as a constant at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/m88rs6000t.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/media/tuners/m88rs6000t.c b/drivers/media/tuners/m88rs6000t.c
index 7e59a9f..8d10798 100644
--- a/drivers/media/tuners/m88rs6000t.c
+++ b/drivers/media/tuners/m88rs6000t.c
@@ -463,13 +463,12 @@ static int m88rs6000t_sleep(struct dvb_frontend *fe)
dev_dbg(&dev->client->dev, "%s:\n", __func__);

ret = regmap_write(dev->regmap, 0x07, 0x6d);
- if (ret)
- goto err;
- usleep_range(5000, 10000);
-err:
- if (ret)
+ if (ret) {
dev_dbg(&dev->client->dev, "failed=%d\n", ret);
- return ret;
+ return ret;
+ }
+ usleep_range(5000, 10000);
+ return 0;
}

static int m88rs6000t_get_frequency(struct dvb_frontend *fe, u32 *frequency)
--
2.6.3

2015-12-28 15:03:24

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] m88rs6000t: Better exception handling in five functions

>> Move the jump label directly before the desired log statement
>> so that the variable "ret" will not be checked once more
>> after a function call.
>
> This commit message fits with the previous change.

Do you prefer an other wording?


> It could be nice to put a blank line before the error handling code.

Is it really a coding style requirement to insert another blank line between
the suggested placement of the statement "return 0;" and the jump label?

Regards,
Markus

2015-12-28 15:12:44

by Julia Lawall

[permalink] [raw]
Subject: Re: [media] m88rs6000t: Better exception handling in five functions

On Mon, 28 Dec 2015, SF Markus Elfring wrote:

> >> Move the jump label directly before the desired log statement
> >> so that the variable "ret" will not be checked once more
> >> after a function call.
> >
> > This commit message fits with the previous change.
>
> Do you prefer an other wording?

Something like "Split the return into success and error cases, to avoid
the need for testing before logging."

The concept of the return being duplicated didn't come across in your
message.

> > It could be nice to put a blank line before the error handling code.
>
> Is it really a coding style requirement to insert another blank line between
> the suggested placement of the statement "return 0;" and the jump label?

I don't think it is a requirement. But some files do it, and if other
functions in this file do it, then it would be nice to do the same.

julia

2015-12-28 16:10:59

by Tejun Heo

[permalink] [raw]
Subject: Re: sata_mv: Another source code review around exception handling?

Hello,

On Fri, Dec 25, 2015 at 05:00:30PM +0100, SF Markus Elfring wrote:
> The value "-ENOMEM" will be returned if one of these function calls failed.
> Can it be that any system resources (like memory) are not appropriately
> released if any calls of this sequence succeeded before the failure?

Most of those are managed resources (devm_, pcim_ and so on) and are
released automatically when the driver detaches from the device.

> Is the use of the single jump label "err" also suspicious here?

And that exit label deal with resources which aren't managed - some
just haven't grown managed variant yet while others don't fit the
model too well.

Thanks.

--
tejun

2015-12-28 16:25:17

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] [media] r820t: Fine-tuning for generic_set_freq()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 17:18:34 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Delete an unnecessary variable initialisation
Better exception handling

drivers/media/tuners/r820t.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

--
2.6.3

2015-12-28 16:30:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] [media] r820t: Delete an unnecessary variable initialisation in generic_set_freq()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 16:36:44 +0100

The variable "rc" will be set to an appropriate value from a call of
the r820t_set_tv_standard() function.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/r820t.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index a7a8452..6ab35e3 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -1295,7 +1295,7 @@ static int generic_set_freq(struct dvb_frontend *fe,
v4l2_std_id std, u32 delsys)
{
struct r820t_priv *priv = fe->tuner_priv;
- int rc = -EINVAL;
+ int rc;
u32 lo_freq;

tuner_dbg("should set frequency to %d kHz, bw %d MHz\n",
--
2.6.3

2015-12-28 16:32:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] [media] r820t: Better exception handling in generic_set_freq()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 17:13:02 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "rc" will not be checked once more
after a function call.
Use the identifier "report_failure" instead of "err".

The error logging is performed in a separate section at the end now.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/r820t.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 6ab35e3..f71642e 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -1303,7 +1303,7 @@ static int generic_set_freq(struct dvb_frontend *fe,

rc = r820t_set_tv_standard(priv, bw, type, std, delsys);
if (rc < 0)
- goto err;
+ goto report_failure;

if ((type == V4L2_TUNER_ANALOG_TV) && (std == V4L2_STD_SECAM_LC))
lo_freq = freq - priv->int_freq;
@@ -1312,23 +1312,21 @@ static int generic_set_freq(struct dvb_frontend *fe,

rc = r820t_set_mux(priv, lo_freq);
if (rc < 0)
- goto err;
+ goto report_failure;

rc = r820t_set_pll(priv, type, lo_freq);
if (rc < 0 || !priv->has_lock)
- goto err;
+ goto report_failure;

rc = r820t_sysfreq_sel(priv, freq, type, std, delsys);
if (rc < 0)
- goto err;
+ goto report_failure;

tuner_dbg("%s: PLL locked on frequency %d Hz, gain=%d\n",
__func__, freq, r820t_read_gain(priv));
-
-err:
-
- if (rc < 0)
- tuner_dbg("%s: failed=%d\n", __func__, rc);
+ return 0;
+report_failure:
+ tuner_dbg("%s: failed=%d\n", __func__, rc);
return rc;
}

--
2.6.3

2015-12-28 19:20:40

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] xc5000: Faster result reporting in xc_load_fw_and_init_tuner()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 20:10:30 +0100

This issue was detected by using the Coccinelle software.

Split the previous if statement at the end so that each final log statement
will eventually be performed by a direct jump to these labels.
* report_failure
* report_success

A check repetition can be excluded for the variable "ret" at the end then.


Apply also two recommendations from the script "checkpatch.pl".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/tuners/xc5000.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index e6e5e90..1360677 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -1166,7 +1166,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)

ret = xc5000_fwupload(fe, desired_fw, fw);
if (ret != 0)
- goto err;
+ goto report_failure;

msleep(20);

@@ -1229,18 +1229,16 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)
/* Default to "CABLE" mode */
ret = xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);
if (!ret)
- break;
+ goto report_success;
printk(KERN_ERR "xc5000: can't set to cable mode.");
}

-err:
- if (!ret)
- printk(KERN_INFO "xc5000: Firmware %s loaded and running.\n",
- desired_fw->name);
- else
- printk(KERN_CONT " - too many retries. Giving up\n");
-
+report_failure:
+ pr_cont(" - too many retries. Giving up\n");
return ret;
+report_success:
+ pr_info("xc5000: Firmware %s loaded and running.\n", desired_fw->name);
+ return 0;
}

static void xc5000_do_timer_sleep(struct work_struct *timer_sleep)
--
2.6.3

2015-12-28 21:16:04

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] airspy: Better exception handling in two functions

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 22:10:28 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "ret" will not be checked once more
after a function call.
Use the identifier "report_failure" instead of "err".

The error logging is performed in a separate section at the end now.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/usb/airspy/airspy.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 0d4ac59..cf2444a 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -889,18 +889,17 @@ static int airspy_set_lna_gain(struct airspy *s)
ret = airspy_ctrl_msg(s, CMD_SET_LNA_AGC, 0, s->lna_gain_auto->val,
&u8tmp, 1);
if (ret)
- goto err;
+ goto report_failure;

if (s->lna_gain_auto->val == false) {
ret = airspy_ctrl_msg(s, CMD_SET_LNA_GAIN, 0, s->lna_gain->val,
&u8tmp, 1);
if (ret)
- goto err;
+ goto report_failure;
}
-err:
- if (ret)
- dev_dbg(s->dev, "failed=%d\n", ret);
-
+ return 0;
+report_failure:
+ dev_dbg(s->dev, "failed=%d\n", ret);
return ret;
}

@@ -916,18 +915,17 @@ static int airspy_set_mixer_gain(struct airspy *s)
ret = airspy_ctrl_msg(s, CMD_SET_MIXER_AGC, 0, s->mixer_gain_auto->val,
&u8tmp, 1);
if (ret)
- goto err;
+ goto report_failure;

if (s->mixer_gain_auto->val == false) {
ret = airspy_ctrl_msg(s, CMD_SET_MIXER_GAIN, 0,
s->mixer_gain->val, &u8tmp, 1);
if (ret)
- goto err;
+ goto report_failure;
}
-err:
- if (ret)
- dev_dbg(s->dev, "failed=%d\n", ret);
-
+ return 0;
+report_failure:
+ dev_dbg(s->dev, "failed=%d\n", ret);
return ret;
}

--
2.6.3

2015-12-28 21:57:03

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] au0828: Refactoring for start_urb_transfer()

From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 22:52:48 +0100

This issue was detected by using the Coccinelle software.

1. Let us return directly if a buffer allocation failed.

2. Delete the jump label "err" then.

3. Drop the explicit initialisation for the variable "ret"
at the beginning.

4. Return zero as a constant at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/usb/au0828/au0828-dvb.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-dvb.c b/drivers/media/usb/au0828/au0828-dvb.c
index cd542b4..e5f1e20 100644
--- a/drivers/media/usb/au0828/au0828-dvb.c
+++ b/drivers/media/usb/au0828/au0828-dvb.c
@@ -181,7 +181,7 @@ static int stop_urb_transfer(struct au0828_dev *dev)
static int start_urb_transfer(struct au0828_dev *dev)
{
struct urb *purb;
- int i, ret = -ENOMEM;
+ int i, ret;

dprintk(2, "%s()\n", __func__);

@@ -194,7 +194,7 @@ static int start_urb_transfer(struct au0828_dev *dev)

dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->urbs[i])
- goto err;
+ return -ENOMEM;

purb = dev->urbs[i];

@@ -207,9 +207,10 @@ static int start_urb_transfer(struct au0828_dev *dev)
if (!purb->transfer_buffer) {
usb_free_urb(purb);
dev->urbs[i] = NULL;
+ ret = -ENOMEM;
pr_err("%s: failed big buffer allocation, err = %d\n",
__func__, ret);
- goto err;
+ return ret;
}

purb->status = -EINPROGRESS;
@@ -235,10 +236,7 @@ static int start_urb_transfer(struct au0828_dev *dev)
}

dev->urb_streaming = true;
- ret = 0;
-
-err:
- return ret;
+ return 0;
}

static void au0828_start_transport(struct au0828_dev *dev)
--
2.6.3

2015-12-29 10:19:07

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] hdpvr: Refactoring for hdpvr_read()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 11:02:43 +0100

Let us return directly if the element "status" of the variable "buf"
indicates "BUFSTAT_READY".
A check repetition can be excluded for the variable "ret" at the end then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/usb/hdpvr/hdpvr-video.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
index 7dee22d..ba7f022 100644
--- a/drivers/media/usb/hdpvr/hdpvr-video.c
+++ b/drivers/media/usb/hdpvr/hdpvr-video.c
@@ -462,10 +462,8 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
}

if (wait_event_interruptible(dev->wait_data,
- buf->status == BUFSTAT_READY)) {
- ret = -ERESTARTSYS;
- goto err;
- }
+ buf->status == BUFSTAT_READY))
+ return -ERESTARTSYS;
}

if (buf->status != BUFSTAT_READY)
--
2.6.3

2015-12-29 11:37:33

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] [media] msi2500: Delete an unnecessary check in msi2500_set_usb_adc()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 12:32:41 +0100

This issue was detected by using the Coccinelle software.

Return the value from a call of the msi2500_ctrl_msg() function
without using an extra check for the variable "ret" at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/usb/msi2500/msi2500.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index c104315..2d33033 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -839,8 +839,6 @@ static int msi2500_set_usb_adc(struct msi2500_dev *dev)
goto err;

ret = msi2500_ctrl_msg(dev, CMD_WREG, reg3);
- if (ret)
- goto err;
err:
return ret;
}
--
2.6.3

2015-12-29 13:04:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] mfd-dm355evm_msp: One function call less in add_child() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 13:56:42 +0100

The platform_device_put() function was called in one case by the
add_child() function during error handling even if the passed
variable "pdev" contained a null pointer.

Implementation details could be improved by the adjustment of jump targets
according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mfd/dm355evm_msp.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index bc90efe..e4aa1b8 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -202,7 +202,7 @@ static struct device *add_child(struct i2c_client *client, const char *name,
if (!pdev) {
dev_dbg(&client->dev, "can't alloc dev\n");
status = -ENOMEM;
- goto err;
+ goto report_failure;
}

device_init_wakeup(&pdev->dev, can_wakeup);
@@ -212,7 +212,7 @@ static struct device *add_child(struct i2c_client *client, const char *name,
status = platform_device_add_data(pdev, pdata, pdata_len);
if (status < 0) {
dev_dbg(&pdev->dev, "can't add platform_data\n");
- goto err;
+ goto put_device;
}
}

@@ -225,19 +225,18 @@ static struct device *add_child(struct i2c_client *client, const char *name,
status = platform_device_add_resources(pdev, &r, 1);
if (status < 0) {
dev_dbg(&pdev->dev, "can't add irq\n");
- goto err;
+ goto put_device;
}
}

status = platform_device_add(pdev);
-
-err:
- if (status < 0) {
- platform_device_put(pdev);
- dev_err(&client->dev, "can't add %s dev\n", name);
- return ERR_PTR(status);
- }
- return &pdev->dev;
+ if (!status)
+ return &pdev->dev;
+put_device:
+ platform_device_put(pdev);
+report_failure:
+ dev_err(&client->dev, "can't add %s dev\n", name);
+ return ERR_PTR(status);
}

static int add_children(struct i2c_client *client)
--
2.6.3

2015-12-29 14:15:35

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:10:48 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Delete an unnecessary variable initialisation
Refactoring

drivers/mfd/smsc-ece1099.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

--
2.6.3

2015-12-29 14:17:08

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] mfd: smsc-ece1099: Delete an unnecessary variable initialisation in smsc_i2c_probe()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 14:47:40 +0100

The variable "ret" will be set to an appropriate value a bit later.
Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mfd/smsc-ece1099.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/smsc-ece1099.c b/drivers/mfd/smsc-ece1099.c
index a4c0df7..bcac488 100644
--- a/drivers/mfd/smsc-ece1099.c
+++ b/drivers/mfd/smsc-ece1099.c
@@ -36,7 +36,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c,
{
struct smsc *smsc;
int devid, rev, venid_l, venid_h;
- int ret = 0;
+ int ret;

smsc = devm_kzalloc(&i2c->dev, sizeof(struct smsc),
GFP_KERNEL);
--
2.6.3

2015-12-29 14:18:30

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 15:03:31 +0100

This issue was detected by using the Coccinelle software.

* Let us return directly if a call of the function "devm_regmap_init_i2c"
or "regmap_write" failed.

* Delete the jump label "err" then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mfd/smsc-ece1099.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/smsc-ece1099.c b/drivers/mfd/smsc-ece1099.c
index bcac488..951333a 100644
--- a/drivers/mfd/smsc-ece1099.c
+++ b/drivers/mfd/smsc-ece1099.c
@@ -46,10 +46,8 @@ static int smsc_i2c_probe(struct i2c_client *i2c,
}

smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
- if (IS_ERR(smsc->regmap)) {
- ret = PTR_ERR(smsc->regmap);
- goto err;
- }
+ if (IS_ERR(smsc->regmap))
+ return PTR_ERR(smsc->regmap);

i2c_set_clientdata(i2c, smsc);
smsc->dev = &i2c->dev;
@@ -68,7 +66,7 @@ static int smsc_i2c_probe(struct i2c_client *i2c,

ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
if (ret)
- goto err;
+ return ret;

#ifdef CONFIG_OF
if (i2c->dev.of_node)
@@ -76,7 +74,6 @@ static int smsc_i2c_probe(struct i2c_client *i2c,
NULL, NULL, &i2c->dev);
#endif

-err:
return ret;
}

--
2.6.3

2015-12-29 18:34:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] mfd: twl-core: One function call less in add_numbered_child() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 19:29:08 +0100

The platform_device_put() function was called in one case by the
add_numbered_child() function during error handling even if the passed
variable "pdev" contained a null pointer.

Implementation details could be improved by the adjustment of jump targets
according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mfd/twl-core.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 831696e..0d9350c 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -625,7 +625,7 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
if (!pdev) {
dev_dbg(&twl->client->dev, "can't alloc dev\n");
status = -ENOMEM;
- goto err;
+ goto report_failure;
}

pdev->dev.parent = &twl->client->dev;
@@ -634,7 +634,7 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
status = platform_device_add_data(pdev, pdata, pdata_len);
if (status < 0) {
dev_dbg(&pdev->dev, "can't add platform_data\n");
- goto err;
+ goto put_device;
}
}

@@ -647,21 +647,20 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
if (status < 0) {
dev_dbg(&pdev->dev, "can't add irqs\n");
- goto err;
+ goto put_device;
}
}

status = platform_device_add(pdev);
- if (status == 0)
+ if (!status) {
device_init_wakeup(&pdev->dev, can_wakeup);
-
-err:
- if (status < 0) {
- platform_device_put(pdev);
- dev_err(&twl->client->dev, "can't add %s dev\n", name);
- return ERR_PTR(status);
+ return &pdev->dev;
}
- return &pdev->dev;
+put_device:
+ platform_device_put(pdev);
+report_failure:
+ dev_err(&twl->client->dev, "can't add %s dev\n", name);
+ return ERR_PTR(status);
}

static inline struct device *add_child(unsigned mod_no, const char *name,
--
2.6.3

2015-12-29 19:50:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] mmc-core: One check less in mmc_select_hs200() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 20:28:46 +0100

This issue was detected by using the Coccinelle software.

Move the jump label directly before the desired log statement
so that the variable "err" will not be checked once more
after it was determined that a call of the function
"__mmc_set_signal_voltage" or "__mmc_switch" failed.
Use the identifier "report_failure" instead of the label "err".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mmc/core/mmc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 549c56e..866f72b 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -1256,7 +1256,7 @@ static int mmc_select_hs200(struct mmc_card *card)

/* If fails try again during next card power cycle */
if (err)
- goto err;
+ goto report_failure;

mmc_select_driver_type(card);

@@ -1276,7 +1276,7 @@ static int mmc_select_hs200(struct mmc_card *card)
card->ext_csd.generic_cmd6_time,
true, send_status, true);
if (err)
- goto err;
+ goto report_failure;
old_timing = host->ios.timing;
mmc_set_timing(host, MMC_TIMING_MMC_HS200);
if (!send_status) {
@@ -1289,10 +1289,11 @@ static int mmc_select_hs200(struct mmc_card *card)
mmc_set_timing(host, old_timing);
}
}
-err:
- if (err)
+ if (err) {
+report_failure:
pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host),
__func__, err);
+ }
return err;
}

--
2.6.3

2015-12-29 20:57:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] mmc-host: Fine-tuning for one function

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 21:54:14 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Delete unnecessary variable initialisations in sdricoh_init_mmc()
Less checks in sdricoh_init_mmc() after error detection

drivers/mmc/host/sdricoh_cs.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

--
2.6.3

2015-12-29 21:00:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] mmc-sdricoh_cs: Delete unnecessary variable initialisations in sdricoh_init_mmc()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 21:11:45 +0100

These variables will eventually be set to an appropriate value a bit later.
* host
* iobase
* result

Thus let us omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mmc/host/sdricoh_cs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index b7e3057..5e57d9f 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -398,10 +398,10 @@ static struct mmc_host_ops sdricoh_ops = {
static int sdricoh_init_mmc(struct pci_dev *pci_dev,
struct pcmcia_device *pcmcia_dev)
{
- int result = 0;
- void __iomem *iobase = NULL;
+ int result;
+ void __iomem *iobase;
struct mmc_host *mmc = NULL;
- struct sdricoh_host *host = NULL;
+ struct sdricoh_host *host;
struct device *dev = &pcmcia_dev->dev;
/* map iomem */
if (pci_resource_len(pci_dev, SDRICOH_PCI_REGION) !=
--
2.6.3

2015-12-29 21:02:45

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] mmc-sdricoh_cs: Less checks in sdricoh_init_mmc() after, error detection

From: Markus Elfring <[email protected]>
Date: Tue, 29 Dec 2015 21:45:34 +0100

This issue was detected by using the Coccinelle software.

Two pointer checks could be repeated by the sdricoh_init_mmc() function
during error handling even if the relevant properties can be determined
for the involved variables before by source code analysis.

* This implementation detail could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Drop an unnecessary initialisation for the variable "mmc" then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mmc/host/sdricoh_cs.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index 5e57d9f..5ff26ab 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -400,7 +400,7 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
{
int result;
void __iomem *iobase;
- struct mmc_host *mmc = NULL;
+ struct mmc_host *mmc;
struct sdricoh_host *host;
struct device *dev = &pcmcia_dev->dev;
/* map iomem */
@@ -419,7 +419,7 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
if (readl(iobase + R104_VERSION) != 0x4000) {
dev_dbg(dev, "no supported mmc controller found\n");
result = -ENODEV;
- goto err;
+ goto unmap_io;
}
/* allocate privdata */
mmc = pcmcia_dev->priv =
@@ -427,7 +427,7 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
if (!mmc) {
dev_err(dev, "mmc_alloc_host failed\n");
result = -ENOMEM;
- goto err;
+ goto unmap_io;
}
host = mmc_priv(mmc);

@@ -451,8 +451,7 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
if (sdricoh_reset(host)) {
dev_dbg(dev, "could not reset\n");
result = -EIO;
- goto err;
-
+ goto free_host;
}

result = mmc_add_host(mmc);
@@ -461,13 +460,10 @@ static int sdricoh_init_mmc(struct pci_dev *pci_dev,
dev_dbg(dev, "mmc host registered\n");
return 0;
}
-
-err:
- if (iobase)
- pci_iounmap(pci_dev, iobase);
- if (mmc)
- mmc_free_host(mmc);
-
+free_host:
+ mmc_free_host(mmc);
+unmap_io:
+ pci_iounmap(pci_dev, iobase);
return result;
}

--
2.6.3

2015-12-31 20:22:20

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] mtd-rfd_ftl: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 31 Dec 2015 21:15:15 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Replace a variable initialisation by assignments
Refactoring for move_block_contents()
Refactoring for erase_block()

drivers/mtd/rfd_ftl.c | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)

--
2.6.3

2015-12-31 20:26:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] mtd-rfd_ftl: Replace a variable initialisation by assignments in move_block_contents()

From: Markus Elfring <[email protected]>
Date: Thu, 31 Dec 2015 20:34:51 +0100

Replace an explicit initialisation for the variable "rc" at the beginning
by assignments that will only be performed if a memory allocation failed.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/rfd_ftl.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index d1cbf26..2927e1b 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -359,17 +359,21 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
void *sector_data;
u16 *map;
size_t retlen;
- int i, rc = -ENOMEM;
+ int i, rc;

part->is_reclaiming = 1;

sector_data = kmalloc(SECTOR_SIZE, GFP_KERNEL);
- if (!sector_data)
+ if (!sector_data) {
+ rc = -ENOMEM;
goto err3;
+ }

map = kmalloc(part->header_size, GFP_KERNEL);
- if (!map)
+ if (!map) {
+ rc = -ENOMEM;
goto err2;
+ }

rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset,
part->header_size, &retlen, (u_char *)map);
--
2.6.3

2015-12-31 20:27:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] mtd-rfd_ftl: Refactoring for move_block_contents()

From: Markus Elfring <[email protected]>
Date: Thu, 31 Dec 2015 20:54:50 +0100

This issue was detected by using the Coccinelle software.

Rename jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/rfd_ftl.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 2927e1b..9b59423 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -366,13 +366,13 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
sector_data = kmalloc(SECTOR_SIZE, GFP_KERNEL);
if (!sector_data) {
rc = -ENOMEM;
- goto err3;
+ goto reset_reclaim;
}

map = kmalloc(part->header_size, GFP_KERNEL);
if (!map) {
rc = -ENOMEM;
- goto err2;
+ goto free_sector;
}

rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset,
@@ -385,8 +385,7 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
printk(KERN_ERR PREFIX "error reading '%s' at "
"0x%lx\n", part->mbd.mtd->name,
part->blocks[block_no].offset);
-
- goto err;
+ goto free_map;
}

for (i=0; i<part->data_sectors_per_block; i++) {
@@ -417,7 +416,6 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
}
rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen,
sector_data);
-
if (!rc && retlen != SECTOR_SIZE)
rc = -EIO;

@@ -425,24 +423,20 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old
printk(KERN_ERR PREFIX "'%s': Unable to "
"read sector for relocation\n",
part->mbd.mtd->name);
-
- goto err;
+ goto free_map;
}

rc = rfd_ftl_writesect((struct mtd_blktrans_dev*)part,
entry, sector_data);
-
if (rc)
- goto err;
+ goto free_map;
}
-
-err:
+free_map:
kfree(map);
-err2:
+free_sector:
kfree(sector_data);
-err3:
+reset_reclaim:
part->is_reclaiming = 0;
-
return rc;
}

--
2.6.3

2015-12-31 20:28:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] mtd-rfd_ftl: Refactoring for erase_block()

From: Markus Elfring <[email protected]>
Date: Thu, 31 Dec 2015 21:06:27 +0100

This issue was detected by using the Coccinelle software.

* Return directly if a memory allocation failed.

* Drop the explicit initialisation for the variable "rc"
at the beginning then.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/rfd_ftl.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 9b59423..8379447 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -326,11 +326,11 @@ static void erase_callback(struct erase_info *erase)
static int erase_block(struct partition *part, int block)
{
struct erase_info *erase;
- int rc = -ENOMEM;
+ int rc;

erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
if (!erase)
- goto err;
+ return -ENOMEM;

erase->mtd = part->mbd.mtd;
erase->callback = erase_callback;
@@ -349,8 +349,6 @@ static int erase_block(struct partition *part, int block)
(unsigned long long)erase->len, part->mbd.mtd->name);
kfree(erase);
}
-
-err:
return rc;
}

--
2.6.3

2015-12-31 21:48:12

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] net-thunder: One check less in nicvf_register_interrupts() after error detection

From: Markus Elfring <[email protected]>
Date: Thu, 31 Dec 2015 22:40:39 +0100

Adjust a jump target to eliminate a check before error logging.
Use the identifier "report_failure" instead of "err".

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/ethernet/cavium/thunder/nicvf_main.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index c24cb2a..21e1579 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -922,7 +922,7 @@ static int nicvf_register_interrupts(struct nicvf *nic)
ret = request_irq(vector, nicvf_intr_handler,
0, nic->irq_name[irq], nic->napi[irq]);
if (ret)
- goto err;
+ goto report_failure;
nic->irq_allocated[irq] = true;
}

@@ -933,7 +933,7 @@ static int nicvf_register_interrupts(struct nicvf *nic)
ret = request_irq(vector, nicvf_rbdr_intr_handler,
0, nic->irq_name[irq], nic);
if (ret)
- goto err;
+ goto report_failure;
nic->irq_allocated[irq] = true;
}

@@ -944,13 +944,12 @@ static int nicvf_register_interrupts(struct nicvf *nic)
ret = request_irq(nic->msix_entries[irq].vector,
nicvf_qs_err_intr_handler,
0, nic->irq_name[irq], nic);
- if (!ret)
+ if (!ret) {
nic->irq_allocated[irq] = true;
-
-err:
- if (ret)
- netdev_err(nic->netdev, "request_irq failed, vector %d\n", irq);
-
+ return 0;
+ }
+report_failure:
+ netdev_err(nic->netdev, "request_irq failed, vector %d\n", irq);
return ret;
}

--
2.6.3

2015-12-31 23:22:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] be2net: Delete an unnecessary check in two functions

From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 00:11:57 +0100

Remove two checks for null pointers which would be handled by usual
error detection before.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/net/ethernet/emulex/benet/be_cmds.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index b63d8ad..ba98297 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -4366,9 +4366,7 @@ int be_cmd_get_profile_config(struct be_adapter *adapter,
if (vf_res)
res->vf_if_cap_flags = vf_res->cap_flags;
err:
- if (cmd.va)
- dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
- cmd.dma);
+ dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
return status;
}

@@ -4398,10 +4396,7 @@ static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
memcpy(req->desc, desc, size);

status = be_cmd_notify_wait(adapter, &wrb);
-
- if (cmd.va)
- dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
- cmd.dma);
+ dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
return status;
}

--
2.6.3

2016-10-01 14:45:06

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 00/15] md-cluster: Fine-tuning for ten function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:38:17 +0200

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (15):
Use kcalloc() in lock_all_bitmaps()
Improve another size determination in resync_info_update()
Improve another size determination in join()
Improve another size determination in __sendmsg()
Improve another size determination in recv_daemon()
Rename a jump label in recv_daemon()
Improve another size determination in process_suspend_info()
Improve determination of sizes in read_resync_info()
Improve another size determination in lockres_init()
Delete an unnecessary variable initialisation in lockres_init()
Delete four error messages for a failed memory allocation
Rename a jump label in area_resyncing()
Less function calls in join() after error detection
Less function calls in lockres_init() after error detection
Delete unnecessary braces in unlock_all_bitmaps()

drivers/md/md-cluster.c | 114 ++++++++++++++++++++++++------------------------
1 file changed, 56 insertions(+), 58 deletions(-)

--
2.10.0

2016-10-01 14:46:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 01/15] md-cluster: Use kcalloc() in lock_all_bitmaps()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:18:40 +0200

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus reuse the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 2b13117..0000e3a 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1188,9 +1188,10 @@ static int lock_all_bitmaps(struct mddev *mddev)
char str[64];
struct md_cluster_info *cinfo = mddev->cluster_info;

- cinfo->other_bitmap_lockres = kzalloc((mddev->bitmap_info.nodes - 1) *
- sizeof(struct dlm_lock_resource *),
- GFP_KERNEL);
+ cinfo->other_bitmap_lockres = kcalloc(mddev->bitmap_info.nodes - 1,
+ sizeof(*cinfo
+ ->other_bitmap_lockres),
+ GFP_KERNEL);
if (!cinfo->other_bitmap_lockres) {
pr_err("md: can't alloc mem for other bitmap locks\n");
return 0;
--
2.10.0

2016-10-01 14:47:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 02/15] md-cluster: Improve another size determination in resync_info_update()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:37:24 +0200

Replace the specification of a data structure by a variable name
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 0000e3a..c28f596 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1057,7 +1057,7 @@ static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)

/* do not send zero again, if we have sent before */
if (hi == 0) {
- memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
+ memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(ri));
if (le64_to_cpu(ri.hi) == 0)
return 0;
}
--
2.10.0

2016-10-01 14:48:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 03/15] md-cluster: Improve another size determination in join()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 11:42:47 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index c28f596..7af27dd 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -823,7 +823,7 @@ static int join(struct mddev *mddev, int nodes)
int ret, ops_rv;
char str[64];

- cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL);
+ cinfo = kzalloc(sizeof(*cinfo), GFP_KERNEL);
if (!cinfo)
return -ENOMEM;

--
2.10.0

2016-10-01 14:49:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 04/15] md-cluster: Improve another size determination in __sendmsg()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:21:48 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 7af27dd..c81eed4 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -706,7 +706,7 @@ static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
}

memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg,
- sizeof(struct cluster_msg));
+ sizeof(*cmsg));
/*down-convert EX to CW on Message*/
error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW);
if (error) {
--
2.10.0

2016-10-01 14:50:23

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 05/15] md-cluster: Improve another size determination in recv_daemon()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:28:19 +0200

Replace the specification of a data structure by a variable name
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index c81eed4..adf9555 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -617,7 +617,7 @@ static void recv_daemon(struct md_thread *thread)
}

/* read lvb and wake up thread to process this message_lockres */
- memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg));
+ memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(msg));
ret = process_recvd_msg(thread->mddev, &msg);
if (ret)
goto out;
--
2.10.0

2016-10-01 14:51:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 06/15] md-cluster: Rename a jump label in recv_daemon()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:36:30 +0200

Adjust a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index adf9555..94835b5 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -620,7 +620,7 @@ static void recv_daemon(struct md_thread *thread)
memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(msg));
ret = process_recvd_msg(thread->mddev, &msg);
if (ret)
- goto out;
+ goto unlock;

/*release CR on ack_lockres*/
ret = dlm_unlock_sync(ack_lockres);
@@ -634,7 +634,7 @@ static void recv_daemon(struct md_thread *thread)
ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR);
if (unlikely(ret != 0))
pr_info("lock CR on ack failed return %d\n", ret);
-out:
+unlock:
/*release CR on message_lockres*/
ret = dlm_unlock_sync(message_lockres);
if (unlikely(ret != 0))
--
2.10.0

2016-10-01 14:52:27

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 07/15] md-cluster: Improve another size determination in process_suspend_info()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:42:50 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 94835b5..e965e78 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -482,8 +482,7 @@ static void process_suspend_info(struct mddev *mddev,
lo, hi);
cinfo->sync_low = lo;
cinfo->sync_hi = hi;
-
- s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
+ s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
return;
s->slot = slot;
--
2.10.0

2016-10-01 14:54:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 08/15] md-cluster: Improve determination of sizes in read_resync_info()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 12:52:58 +0200

Replace the specification of data structures by either a pointer
dereference or a variable name as the parameter for the operator "sizeof"
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index e965e78..0918108 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -275,10 +275,10 @@ static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_loc
sector_t hi = 0;

dlm_lock_sync(lockres, DLM_LOCK_CR);
- memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
+ memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(ri));
hi = le64_to_cpu(ri.hi);
if (hi > 0) {
- s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
+ s = kzalloc(sizeof(*s), GFP_KERNEL);
if (!s)
goto out;
s->hi = hi;
--
2.10.0

2016-10-01 14:54:28

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 09/15] md-cluster: Improve another size determination in lockres_init()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:02:18 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 0918108..bec8035 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -190,7 +190,7 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
int ret, namelen;
struct md_cluster_info *cinfo = mddev->cluster_info;

- res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
+ res = kzalloc(sizeof(*res), GFP_KERNEL);
if (!res)
return NULL;
init_waitqueue_head(&res->sync_locking);
--
2.10.0

2016-10-01 14:55:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 10/15] md-cluster: Delete an unnecessary variable initialisation in lockres_init()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:07:52 +0200

The local variable "res" will be set to an appropriate pointer a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index bec8035..b91b552 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -186,7 +186,7 @@ static int dlm_lock_sync_interruptible(struct dlm_lock_resource *res, int mode,
static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
char *name, void (*bastfn)(void *arg, int mode), int with_lvb)
{
- struct dlm_lock_resource *res = NULL;
+ struct dlm_lock_resource *res;
int ret, namelen;
struct md_cluster_info *cinfo = mddev->cluster_info;

--
2.10.0

2016-10-01 14:56:51

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 11/15] md-cluster: Delete four error messages for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 13:46:20 +0200

Omit extra messages for a memory allocation failure in three functions.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index b91b552..7f82c6b 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -200,17 +200,13 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
res->mode = DLM_LOCK_IV;
namelen = strlen(name);
res->name = kzalloc(namelen + 1, GFP_KERNEL);
- if (!res->name) {
- pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name);
+ if (!res->name)
goto out_err;
- }
strlcpy(res->name, name, namelen + 1);
if (with_lvb) {
res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL);
- if (!res->lksb.sb_lvbptr) {
- pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name);
+ if (!res->lksb.sb_lvbptr)
goto out_err;
- }
res->flags = DLM_LKF_VALBLK;
}

@@ -852,10 +848,8 @@ static int join(struct mddev *mddev, int nodes)
/* Initiate the communication resources */
ret = -ENOMEM;
cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
- if (!cinfo->recv_thread) {
- pr_err("md-cluster: cannot allocate memory for recv_thread!\n");
+ if (!cinfo->recv_thread)
goto err;
- }
cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
if (!cinfo->message_lockres)
goto err;
@@ -1191,10 +1185,8 @@ static int lock_all_bitmaps(struct mddev *mddev)
sizeof(*cinfo
->other_bitmap_lockres),
GFP_KERNEL);
- if (!cinfo->other_bitmap_lockres) {
- pr_err("md: can't alloc mem for other bitmap locks\n");
+ if (!cinfo->other_bitmap_lockres)
return 0;
- }

my_slot = slot_number(mddev);
for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) {
--
2.10.0

2016-10-01 14:57:49

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 12/15] md-cluster: Rename a jump label in area_resyncing()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 14:38:12 +0200

Adjust a jump label according to the Linux coding style convention

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 7f82c6b..e1ebcc4 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1085,13 +1085,13 @@ static int area_resyncing(struct mddev *mddev, int direction,

spin_lock_irq(&cinfo->suspend_lock);
if (list_empty(&cinfo->suspend_list))
- goto out;
+ goto unlock;
list_for_each_entry(s, &cinfo->suspend_list, list)
if (hi > s->lo && lo < s->hi) {
ret = 1;
break;
}
-out:
+unlock:
spin_unlock_irq(&cinfo->suspend_lock);
return ret;
}
--
2.10.0

2016-10-01 14:59:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 13/15] md-cluster: Less function calls in join() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 15:40:32 +0200

A few resource release functions were called in some cases
by the join() function during error handling
even if the passed data structure member contained a null pointer.

* Adjust jump targets according to the Linux coding style convention.

* Delete a repeated check which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index e1ebcc4..36bb962 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -837,39 +837,39 @@ static int join(struct mddev *mddev, int nodes)
DLM_LSFL_FS, LVB_SIZE,
&md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);
if (ret)
- goto err;
+ goto free_cluster_info;
wait_for_completion(&cinfo->completion);
if (nodes < cinfo->slot_number) {
pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).",
cinfo->slot_number, nodes);
ret = -ERANGE;
- goto err;
+ goto release_lockspace;
}
/* Initiate the communication resources */
ret = -ENOMEM;
cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
if (!cinfo->recv_thread)
- goto err;
+ goto release_lockspace;
cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
if (!cinfo->message_lockres)
- goto err;
+ goto unregister_recv;
cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0);
if (!cinfo->token_lockres)
- goto err;
+ goto free_message;
cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0);
if (!cinfo->no_new_dev_lockres)
- goto err;
+ goto free_token;

ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
if (ret) {
ret = -EAGAIN;
pr_err("md-cluster: can't join cluster to avoid lock issue\n");
- goto err;
+ goto free_no_new_dev;
}
cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0);
if (!cinfo->ack_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_no_new_dev;
}
/* get sync CR lock on ACK. */
if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR))
@@ -886,34 +886,39 @@ static int join(struct mddev *mddev, int nodes)
cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1);
if (!cinfo->bitmap_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_ack;
}
if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) {
pr_err("Failed to get bitmap lock\n");
ret = -EINVAL;
- goto err;
+ goto free_bitmap;
}

cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0);
if (!cinfo->resync_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_bitmap;
}

return 0;
-err:
- md_unregister_thread(&cinfo->recovery_thread);
- md_unregister_thread(&cinfo->recv_thread);
- lockres_free(cinfo->message_lockres);
- lockres_free(cinfo->token_lockres);
+free_bitmap:
+ lockres_free(cinfo->bitmap_lockres);
+free_ack:
lockres_free(cinfo->ack_lockres);
+free_no_new_dev:
lockres_free(cinfo->no_new_dev_lockres);
- lockres_free(cinfo->resync_lockres);
- lockres_free(cinfo->bitmap_lockres);
- if (cinfo->lockspace)
- dlm_release_lockspace(cinfo->lockspace, 2);
- mddev->cluster_info = NULL;
+free_token:
+ lockres_free(cinfo->token_lockres);
+free_message:
+ lockres_free(cinfo->message_lockres);
+unregister_recv:
+ md_unregister_thread(&cinfo->recv_thread);
+release_lockspace:
+ dlm_release_lockspace(cinfo->lockspace, 2);
+free_cluster_info:
kfree(cinfo);
+ md_unregister_thread(&cinfo->recovery_thread);
+ mddev->cluster_info = NULL;
return ret;
}

--
2.10.0

2016-10-01 14:59:41

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 14/15] md-cluster: Less function calls in lockres_init() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:01:05 +0200

The kfree() function was called in up to three cases
by the lockres_init() function during error handling even if
the passed data structure member (or variable) contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 36bb962..0cade1a 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -201,12 +201,12 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
namelen = strlen(name);
res->name = kzalloc(namelen + 1, GFP_KERNEL);
if (!res->name)
- goto out_err;
+ goto free_resource;
strlcpy(res->name, name, namelen + 1);
if (with_lvb) {
res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL);
if (!res->lksb.sb_lvbptr)
- goto out_err;
+ goto free_name;
res->flags = DLM_LKF_VALBLK;
}

@@ -218,15 +218,17 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
ret = dlm_lock_sync(res, DLM_LOCK_NL);
if (ret) {
pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name);
- goto out_err;
+ goto free_lvb;
}
res->flags &= ~DLM_LKF_EXPEDITE;
res->flags |= DLM_LKF_CONVERT;

return res;
-out_err:
+free_lvb:
kfree(res->lksb.sb_lvbptr);
+free_name:
kfree(res->name);
+free_resource:
kfree(res);
return NULL;
}
--
2.10.0

2016-10-01 15:00:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 15/15] md-cluster: Delete unnecessary braces in unlock_all_bitmaps()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 16:15:55 +0200

Do not use curly brackets at one source code place
where a single statement should be sufficient.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-cluster.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 0cade1a..a9bf13d 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1223,11 +1223,10 @@ static void unlock_all_bitmaps(struct mddev *mddev)

/* release other node's bitmap lock if they are existed */
if (cinfo->other_bitmap_lockres) {
- for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) {
- if (cinfo->other_bitmap_lockres[i]) {
+ for (i = 0; i < mddev->bitmap_info.nodes - 1; i++)
+ if (cinfo->other_bitmap_lockres[i])
lockres_free(cinfo->other_bitmap_lockres[i]);
- }
- }
+
kfree(cinfo->other_bitmap_lockres);
}
}
--
2.10.0

2016-10-02 11:55:20

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 00/13] md/multipath: Fine-tuning for several function implementations

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 13:45:35 +0200

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (13):
Use kcalloc() in multipath_run()
Improve another size determination in multipath_run()
Delete four error messages for a failed memory allocation
Reduce indentation for four lines in multipath_run()
Less function calls in multipath_run() after error detection
Delete 13 unwanted spaces behind function names
Delete two unwanted spaces behind asterisks
Replace a seq_printf() call by seq_puts() in multipath_status()
Adjust two function calls together with a variable assignment
Add some spaces for better code readability
Move a brace for a designated initialiser
Delete an unnecessary return statement in multipath_make_request()
Replace printk() calls by the usage of higher level interfaces

drivers/md/multipath.c | 192 +++++++++++++++++++++++--------------------------
1 file changed, 88 insertions(+), 104 deletions(-)

--
2.10.0

2016-10-02 11:57:28

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/13] md/multipath: Use kcalloc() in multipath_run()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:40:42 +0200

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus reuse the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 673efbd..bd53451 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -408,7 +408,8 @@ static int multipath_run (struct mddev *mddev)
goto out;
}

- conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks,
+ conf->multipaths = kcalloc(mddev->raid_disks,
+ sizeof(*conf->multipaths),
GFP_KERNEL);
if (!conf->multipaths) {
printk(KERN_ERR
--
2.10.0

2016-10-02 11:58:09

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/13] md/multipath: Improve another size determination in multipath_run()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 20:52:57 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index bd53451..7fdabb1 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -399,7 +399,7 @@ static int multipath_run (struct mddev *mddev)
* should be freed in multipath_free()]
*/

- conf = kzalloc(sizeof(struct mpconf), GFP_KERNEL);
+ conf = kzalloc(sizeof(*conf), GFP_KERNEL);
mddev->private = conf;
if (!conf) {
printk(KERN_ERR
--
2.10.0

2016-10-02 11:59:39

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/13] md/multipath: Delete four error messages for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:15:45 +0200

Omit extra messages for a memory allocation failure in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 7fdabb1..be7c0b9 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -401,22 +401,14 @@ static int multipath_run (struct mddev *mddev)

conf = kzalloc(sizeof(*conf), GFP_KERNEL);
mddev->private = conf;
- if (!conf) {
- printk(KERN_ERR
- "multipath: couldn't allocate memory for %s\n",
- mdname(mddev));
+ if (!conf)
goto out;
- }

conf->multipaths = kcalloc(mddev->raid_disks,
sizeof(*conf->multipaths),
GFP_KERNEL);
- if (!conf->multipaths) {
- printk(KERN_ERR
- "multipath: couldn't allocate memory for %s\n",
- mdname(mddev));
+ if (!conf->multipaths)
goto out_free_conf;
- }

working_disks = 0;
rdev_for_each(rdev, mddev) {
@@ -448,21 +440,14 @@ static int multipath_run (struct mddev *mddev)

conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS,
sizeof(struct multipath_bh));
- if (conf->pool == NULL) {
- printk(KERN_ERR
- "multipath: couldn't allocate memory for %s\n",
- mdname(mddev));
+ if (!conf->pool)
goto out_free_conf;
- }

{
mddev->thread = md_register_thread(multipathd, mddev,
"multipath");
- if (!mddev->thread) {
- printk(KERN_ERR "multipath: couldn't allocate thread"
- " for %s\n", mdname(mddev));
+ if (!mddev->thread)
goto out_free_conf;
- }
}

printk(KERN_INFO
--
2.10.0

2016-10-02 12:00:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/13] md/multipath: Reduce indentation for four lines in multipath_run()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:26:00 +0200

* Delete a pair of extra curly brackets.

* Reduce indentation one level for a few lines in this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index be7c0b9..7900426 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -443,12 +443,9 @@ static int multipath_run (struct mddev *mddev)
if (!conf->pool)
goto out_free_conf;

- {
- mddev->thread = md_register_thread(multipathd, mddev,
- "multipath");
- if (!mddev->thread)
- goto out_free_conf;
- }
+ mddev->thread = md_register_thread(multipathd, mddev, "multipath");
+ if (!mddev->thread)
+ goto out_free_conf;

printk(KERN_INFO
"multipath: array %s active with %d out of %d IO paths\n",
--
2.10.0

2016-10-02 12:01:30

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/13] md/multipath: Less function calls in multipath_run() after error detection

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 21:48:59 +0200

The functions "kfree" and "mempool_destroy" were called in a few cases
by the function "multipath_run" during error handling even if
the passed data structure member contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 7900426..2e4ceb9 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -408,7 +408,7 @@ static int multipath_run (struct mddev *mddev)
sizeof(*conf->multipaths),
GFP_KERNEL);
if (!conf->multipaths)
- goto out_free_conf;
+ goto free_conf;

working_disks = 0;
rdev_for_each(rdev, mddev) {
@@ -434,18 +434,18 @@ static int multipath_run (struct mddev *mddev)
if (!working_disks) {
printk(KERN_ERR "multipath: no operational IO paths for %s\n",
mdname(mddev));
- goto out_free_conf;
+ goto free_multipaths;
}
mddev->degraded = conf->raid_disks - working_disks;

conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS,
sizeof(struct multipath_bh));
if (!conf->pool)
- goto out_free_conf;
+ goto free_multipaths;

mddev->thread = md_register_thread(multipathd, mddev, "multipath");
if (!mddev->thread)
- goto out_free_conf;
+ goto destroy_pool;

printk(KERN_INFO
"multipath: array %s active with %d out of %d IO paths\n",
@@ -457,13 +457,14 @@ static int multipath_run (struct mddev *mddev)
md_set_array_sectors(mddev, multipath_size(mddev, 0, 0));

if (md_integrity_register(mddev))
- goto out_free_conf;
+ goto destroy_pool;

return 0;
-
-out_free_conf:
+destroy_pool:
mempool_destroy(conf->pool);
+free_multipaths:
kfree(conf->multipaths);
+free_conf:
kfree(conf);
mddev->private = NULL;
out:
--
2.10.0

2016-10-02 12:02:27

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/13] md/multipath: Delete 13 unwanted spaces behind function names

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 08:14:48 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: space prohibited between function name and open parenthesis '('

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 2e4ceb9..7e10603 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -31,7 +31,7 @@

#define NR_RESERVED_BUFS 32

-static int multipath_map (struct mpconf *conf)
+static int multipath_map(struct mpconf *conf)
{
int i, disks = conf->raid_disks;

@@ -56,7 +56,7 @@ static int multipath_map (struct mpconf *conf)
return (-1);
}

-static void multipath_reschedule_retry (struct multipath_bh *mp_bh)
+static void multipath_reschedule_retry(struct multipath_bh *mp_bh)
{
unsigned long flags;
struct mddev *mddev = mp_bh->mddev;
@@ -73,7 +73,7 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh)
* operation and are ready to return a success/failure code to the buffer
* cache layer.
*/
-static void multipath_end_bh_io (struct multipath_bh *mp_bh, int err)
+static void multipath_end_bh_io(struct multipath_bh *mp_bh, int err)
{
struct bio *bio = mp_bh->master_bio;
struct mpconf *conf = mp_bh->mddev->private;
@@ -96,7 +96,7 @@ static void multipath_end_request(struct bio *bio)
* oops, IO error:
*/
char b[BDEVNAME_SIZE];
- md_error (mp_bh->mddev, rdev);
+ md_error(mp_bh->mddev, rdev);
printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n",
bdevname(rdev->bdev,b),
(unsigned long long)bio->bi_iter.bi_sector);
@@ -147,12 +147,14 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)
struct mpconf *conf = mddev->private;
int i;

- seq_printf (seq, " [%d/%d] [", conf->raid_disks,
- conf->raid_disks - mddev->degraded);
+ seq_printf(seq, " [%d/%d] [", conf->raid_disks,
+ conf->raid_disks - mddev->degraded);
rcu_read_lock();
for (i = 0; i < conf->raid_disks; i++) {
struct md_rdev *rdev = rcu_dereference(conf->multipaths[i].rdev);
- seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
+ seq_printf(seq,
+ "%s",
+ rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
seq_printf (seq, "]");
@@ -183,7 +185,7 @@ static int multipath_congested(struct mddev *mddev, int bits)
/*
* Careful, this can execute in IRQ contexts as well!
*/
-static void multipath_error (struct mddev *mddev, struct md_rdev *rdev)
+static void multipath_error(struct mddev *mddev, struct md_rdev *rdev)
{
struct mpconf *conf = mddev->private;
char b[BDEVNAME_SIZE];
@@ -218,7 +220,7 @@ static void multipath_error (struct mddev *mddev, struct md_rdev *rdev)
conf->raid_disks - mddev->degraded);
}

-static void print_multipath_conf (struct mpconf *conf)
+static void print_multipath_conf(struct mpconf *conf)
{
int i;
struct multipath_info *tmp;
@@ -377,7 +379,7 @@ static sector_t multipath_size(struct mddev *mddev, sector_t sectors, int raid_d
return mddev->dev_sectors;
}

-static int multipath_run (struct mddev *mddev)
+static int multipath_run(struct mddev *mddev)
{
struct mpconf *conf;
int disk_idx;
@@ -496,14 +498,14 @@ static struct md_personality multipath_personality =
.congested = multipath_congested,
};

-static int __init multipath_init (void)
+static int __init multipath_init(void)
{
- return register_md_personality (&multipath_personality);
+ return register_md_personality(&multipath_personality);
}

-static void __exit multipath_exit (void)
+static void __exit multipath_exit(void)
{
- unregister_md_personality (&multipath_personality);
+ unregister_md_personality(&multipath_personality);
}

module_init(multipath_init);
--
2.10.0

2016-10-02 12:04:27

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 7/13] md/multipath: Delete two unwanted spaces behind asterisks

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 09:39:39 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: "foo * bar" should be "foo *bar"

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 7e10603..cb5141f 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -106,10 +106,10 @@ static void multipath_end_request(struct bio *bio)
rdev_dec_pending(rdev, conf->mddev);
}

-static void multipath_make_request(struct mddev *mddev, struct bio * bio)
+static void multipath_make_request(struct mddev *mddev, struct bio *bio)
{
struct mpconf *conf = mddev->private;
- struct multipath_bh * mp_bh;
+ struct multipath_bh *mp_bh;
struct multipath_info *multipath;

if (unlikely(bio->bi_opf & REQ_PREFLUSH)) {
--
2.10.0

2016-10-02 12:04:49

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 8/13] md/multipath: Replace a seq_printf() call by seq_puts() in multipath_status()

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:00:15 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index cb5141f..0e8939f 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)
rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf (seq, "]");
+ seq_puts(seq, "]");
}

static int multipath_congested(struct mddev *mddev, int bits)
--
2.10.0

2016-10-02 12:05:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 9/13] md/multipath: Adjust two function calls together with a variable assignment

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:05:43 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 0e8939f..a5a639d 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -258,8 +258,9 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)

print_multipath_conf(conf);

- for (path = first; path <= last; path++)
- if ((p=conf->multipaths+path)->rdev == NULL) {
+ for (path = first; path <= last; path++) {
+ p = conf->multipaths + path;
+ if (!p->rdev) {
q = rdev->bdev->bd_disk->queue;
disk_stack_limits(mddev->gendisk, rdev->bdev,
rdev->data_offset << 9);
@@ -276,6 +277,7 @@ static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)
err = 0;
break;
}
+ }

print_multipath_conf(conf);

@@ -347,7 +349,8 @@ static void multipathd(struct md_thread *thread)
bio = &mp_bh->bio;
bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector;

- if ((mp_bh->path = multipath_map (conf))<0) {
+ mp_bh->path = multipath_map(conf);
+ if (mp_bh->path < 0) {
printk(KERN_ALERT "multipath: %s: unrecoverable IO read"
" error for block %llu\n",
bdevname(bio->bi_bdev,b),
--
2.10.0

2016-10-02 12:06:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 10/13] md/multipath: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:20:52 +0200

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index a5a639d..23c7c29 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -98,7 +98,7 @@ static void multipath_end_request(struct bio *bio)
char b[BDEVNAME_SIZE];
md_error(mp_bh->mddev, rdev);
printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n",
- bdevname(rdev->bdev,b),
+ bdevname(rdev->bdev, b),
(unsigned long long)bio->bi_iter.bi_sector);
multipath_reschedule_retry(mp_bh);
} else
@@ -238,8 +238,8 @@ static void print_multipath_conf(struct mpconf *conf)
tmp = conf->multipaths + i;
if (tmp->rdev)
printk(" disk%d, o:%d, dev:%s\n",
- i,!test_bit(Faulty, &tmp->rdev->flags),
- bdevname(tmp->rdev->bdev,b));
+ i, !test_bit(Faulty, &tmp->rdev->flags),
+ bdevname(tmp->rdev->bdev, b));
}
}

@@ -353,13 +353,13 @@ static void multipathd(struct md_thread *thread)
if (mp_bh->path < 0) {
printk(KERN_ALERT "multipath: %s: unrecoverable IO read"
" error for block %llu\n",
- bdevname(bio->bi_bdev,b),
+ bdevname(bio->bi_bdev, b),
(unsigned long long)bio->bi_iter.bi_sector);
multipath_end_bh_io(mp_bh, -EIO);
} else {
printk(KERN_ERR "multipath: %s: redirecting sector %llu"
" to another IO path\n",
- bdevname(bio->bi_bdev,b),
+ bdevname(bio->bi_bdev, b),
(unsigned long long)bio->bi_iter.bi_sector);
*bio = *(mp_bh->master_bio);
bio->bi_iter.bi_sector +=
@@ -487,18 +487,18 @@ static void multipath_free(struct mddev *mddev, void *priv)

static struct md_personality multipath_personality =
{
- .name = "multipath",
- .level = LEVEL_MULTIPATH,
- .owner = THIS_MODULE,
- .make_request = multipath_make_request,
- .run = multipath_run,
- .free = multipath_free,
- .status = multipath_status,
- .error_handler = multipath_error,
- .hot_add_disk = multipath_add_disk,
- .hot_remove_disk= multipath_remove_disk,
- .size = multipath_size,
- .congested = multipath_congested,
+ .name = "multipath",
+ .level = LEVEL_MULTIPATH,
+ .owner = THIS_MODULE,
+ .make_request = multipath_make_request,
+ .run = multipath_run,
+ .free = multipath_free,
+ .status = multipath_status,
+ .error_handler = multipath_error,
+ .hot_add_disk = multipath_add_disk,
+ .hot_remove_disk = multipath_remove_disk,
+ .size = multipath_size,
+ .congested = multipath_congested,
};

static int __init multipath_init(void)
--
2.10.0

2016-10-02 12:08:48

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 11/13] md/multipath: Move a brace for a designated initialiser

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:43:28 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: that open brace { should be on the previous line

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 23c7c29..ab6487c 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -485,8 +485,7 @@ static void multipath_free(struct mddev *mddev, void *priv)
kfree(conf);
}

-static struct md_personality multipath_personality =
-{
+static struct md_personality multipath_personality = {
.name = "multipath",
.level = LEVEL_MULTIPATH,
.owner = THIS_MODULE,
--
2.10.0

2016-10-02 12:09:47

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 12/13] md/multipath: Delete an unnecessary return statement in multipath_make_request()

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 10:55:06 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement here.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index ab6487c..85f6c85 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -139,7 +139,6 @@ static void multipath_make_request(struct mddev *mddev, struct bio *bio)
mp_bh->bio.bi_end_io = multipath_end_request;
mp_bh->bio.bi_private = mp_bh;
generic_make_request(&mp_bh->bio);
- return;
}

static void multipath_status(struct seq_file *seq, struct mddev *mddev)
--
2.10.0

2016-10-02 12:10:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 13/13] md/multipath: Replace printk() calls by the usage of higher level interfaces

From: Markus Elfring <[email protected]>
Date: Sun, 2 Oct 2016 12:42:46 +0200

1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt"
so that their information can be used for consistent message output.

2. Prefer usage of some higher level macros over calling "printk" directly
in this software module.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/multipath.c | 69 ++++++++++++++++++++++++--------------------------
1 file changed, 33 insertions(+), 36 deletions(-)

diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 85f6c85..045b866 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -19,6 +19,8 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

+#define MY_LOG_PREFIX KBUILD_MODNAME ": "
+#define pr_fmt(fmt) MY_LOG_PREFIX fmt
#include <linux/blkdev.h>
#include <linux/module.h>
#include <linux/raid/md_u.h>
@@ -51,8 +53,7 @@ static int multipath_map(struct mpconf *conf)
}
}
rcu_read_unlock();
-
- printk(KERN_ERR "multipath_map(): no more operational IO paths?\n");
+ pr_err("map: no more operational IO paths?\n");
return (-1);
}

@@ -97,7 +98,8 @@ static void multipath_end_request(struct bio *bio)
*/
char b[BDEVNAME_SIZE];
md_error(mp_bh->mddev, rdev);
- printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n",
+
+ pr_err("%s: rescheduling sector %llu\n",
bdevname(rdev->bdev, b),
(unsigned long long)bio->bi_iter.bi_sector);
multipath_reschedule_retry(mp_bh);
@@ -195,8 +197,7 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev)
* first check if this is a queued request for a device
* which has just failed.
*/
- printk(KERN_ALERT
- "multipath: only one IO path left and IO error.\n");
+ pr_alert("only one IO path left and IO error.\n");
/* leave it active... it's all we have */
return;
}
@@ -211,12 +212,10 @@ static void multipath_error(struct mddev *mddev, struct md_rdev *rdev)
}
set_bit(Faulty, &rdev->flags);
set_bit(MD_CHANGE_DEVS, &mddev->flags);
- printk(KERN_ALERT "multipath: IO failure on %s,"
- " disabling IO path.\n"
- "multipath: Operation continuing"
- " on %d IO paths.\n",
- bdevname(rdev->bdev, b),
- conf->raid_disks - mddev->degraded);
+ pr_alert("IO failure on %s, disabling IO path.\n"
+ MY_LOG_PREFIX "Operation continuing on %d IO paths.\n",
+ bdevname(rdev->bdev, b),
+ conf->raid_disks - mddev->degraded);
}

static void print_multipath_conf(struct mpconf *conf)
@@ -224,21 +223,22 @@ static void print_multipath_conf(struct mpconf *conf)
int i;
struct multipath_info *tmp;

- printk("MULTIPATH conf printout:\n");
+ pr_info("conf printout:\n");
if (!conf) {
- printk("(conf==NULL)\n");
+ pr_info("(conf==NULL)\n");
return;
}
- printk(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded,
- conf->raid_disks);
+ pr_info("--- wd:%d rd:%d\n",
+ conf->raid_disks - conf->mddev->degraded,
+ conf->raid_disks);

for (i = 0; i < conf->raid_disks; i++) {
char b[BDEVNAME_SIZE];
tmp = conf->multipaths + i;
if (tmp->rdev)
- printk(" disk%d, o:%d, dev:%s\n",
- i, !test_bit(Faulty, &tmp->rdev->flags),
- bdevname(tmp->rdev->bdev, b));
+ pr_info("disk%d, o:%d, dev:%s\n",
+ i, !test_bit(Faulty, &tmp->rdev->flags),
+ bdevname(tmp->rdev->bdev, b));
}
}

@@ -295,8 +295,8 @@ static int multipath_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
if (rdev == p->rdev) {
if (test_bit(In_sync, &rdev->flags) ||
atomic_read(&rdev->nr_pending)) {
- printk(KERN_ERR "hot-remove-disk, slot %d is identified"
- " but is still operational!\n", number);
+ pr_err("hot-remove-disk, slot %d is identified but is still operational!\n",
+ number);
err = -EBUSY;
goto abort;
}
@@ -350,16 +350,14 @@ static void multipathd(struct md_thread *thread)

mp_bh->path = multipath_map(conf);
if (mp_bh->path < 0) {
- printk(KERN_ALERT "multipath: %s: unrecoverable IO read"
- " error for block %llu\n",
- bdevname(bio->bi_bdev, b),
- (unsigned long long)bio->bi_iter.bi_sector);
+ pr_alert("%s: unrecoverable IO read error for block %llu\n",
+ bdevname(bio->bi_bdev, b),
+ (unsigned long long)bio->bi_iter.bi_sector);
multipath_end_bh_io(mp_bh, -EIO);
} else {
- printk(KERN_ERR "multipath: %s: redirecting sector %llu"
- " to another IO path\n",
- bdevname(bio->bi_bdev, b),
- (unsigned long long)bio->bi_iter.bi_sector);
+ pr_err("%s: redirecting sector %llu to another IO path\n",
+ bdevname(bio->bi_bdev, b),
+ (unsigned long long)bio->bi_iter.bi_sector);
*bio = *(mp_bh->master_bio);
bio->bi_iter.bi_sector +=
conf->multipaths[mp_bh->path].rdev->data_offset;
@@ -393,8 +391,8 @@ static int multipath_run(struct mddev *mddev)
return -EINVAL;

if (mddev->level != LEVEL_MULTIPATH) {
- printk("multipath: %s: raid level not set to multipath IO (%d)\n",
- mdname(mddev), mddev->level);
+ pr_notice("%s: raid level not set to multipath IO (%d)\n",
+ mdname(mddev), mddev->level);
goto out;
}
/*
@@ -436,8 +434,7 @@ static int multipath_run(struct mddev *mddev)
INIT_LIST_HEAD(&conf->retry_list);

if (!working_disks) {
- printk(KERN_ERR "multipath: no operational IO paths for %s\n",
- mdname(mddev));
+ pr_err("no operational IO paths for %s\n", mdname(mddev));
goto free_multipaths;
}
mddev->degraded = conf->raid_disks - working_disks;
@@ -451,10 +448,10 @@ static int multipath_run(struct mddev *mddev)
if (!mddev->thread)
goto destroy_pool;

- printk(KERN_INFO
- "multipath: array %s active with %d out of %d IO paths\n",
- mdname(mddev), conf->raid_disks - mddev->degraded,
- mddev->raid_disks);
+ pr_info("array %s active with %d out of %d IO paths\n",
+ mdname(mddev),
+ conf->raid_disks - mddev->degraded,
+ mddev->raid_disks);
/*
* Ok, everything is just fine now
*/
--
2.10.0

2016-10-06 08:50:03

by Christoph Hellwig

[permalink] [raw]
Subject: Re: MD-RAID: Fine-tuning for several function implementations

Please stop it NOW. This is not fine tuning but a waste of everyones
time.

2016-10-06 08:54:33

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 02/54] md/raid0: Less function calls in create_strip_zones() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 10:43:33 +0200

The kfree() function was called in up to two cases
by the create_strip_zones() function during error handling even if
the passed data structure member (or variable) contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 50e8a63..3c76451 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -146,7 +146,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
mdname(mddev),
mddev->chunk_sectors << 9, blksize);
err = -EINVAL;
- goto abort;
+ goto free_conf;
}

err = -ENOMEM;
@@ -154,12 +154,12 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
sizeof(*conf->strip_zone),
GFP_KERNEL);
if (!conf->strip_zone)
- goto abort;
+ goto free_conf;
conf->devlist = kcalloc(conf->nr_strip_zones * mddev->raid_disks,
sizeof(*conf->devlist),
GFP_KERNEL);
if (!conf->devlist)
- goto abort;
+ goto free_zone;

/* The first zone must contain all devices, so here we check that
* there is a proper alignment of slots to devices and find them all
@@ -190,17 +190,17 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
printk(KERN_ERR
"md/raid0:%s: remove inactive devices before converting to RAID0\n",
mdname(mddev));
- goto abort;
+ goto free_device_list;
}
if (j >= mddev->raid_disks) {
printk(KERN_ERR "md/raid0:%s: bad disk number %d - "
"aborting!\n", mdname(mddev), j);
- goto abort;
+ goto free_device_list;
}
if (dev[j]) {
printk(KERN_ERR "md/raid0:%s: multiple devices for %d - "
"aborting!\n", mdname(mddev), j);
- goto abort;
+ goto free_device_list;
}
dev[j] = rdev1;

@@ -211,7 +211,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
if (cnt != mddev->raid_disks) {
printk(KERN_ERR "md/raid0:%s: too few disks (%d of %d) - "
"aborting!\n", mdname(mddev), cnt, mddev->raid_disks);
- goto abort;
+ goto free_device_list;
}
zone->nb_dev = cnt;
zone->zone_end = smallest->sectors * cnt;
@@ -271,9 +271,11 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
*private_conf = conf;

return 0;
-abort:
- kfree(conf->strip_zone);
+free_device_list:
kfree(conf->devlist);
+free_zone:
+ kfree(conf->strip_zone);
+free_conf:
kfree(conf);
*private_conf = ERR_PTR(err);
return err;
--
2.10.1

2016-10-06 08:55:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 03/54] md/raid0: Move a variable assignment in create_strip_zones()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 12:02:29 +0200

One local variable was set to an error code before a concrete
error situation was detected. Thus move the corresponding assignment into
two if branches to indicate a memory allocation failure there.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 3c76451..71bd398 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -149,17 +149,21 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
goto free_conf;
}

- err = -ENOMEM;
conf->strip_zone = kcalloc(conf->nr_strip_zones,
sizeof(*conf->strip_zone),
GFP_KERNEL);
- if (!conf->strip_zone)
+ if (!conf->strip_zone) {
+ err = -ENOMEM;
goto free_conf;
+ }
+
conf->devlist = kcalloc(conf->nr_strip_zones * mddev->raid_disks,
sizeof(*conf->devlist),
GFP_KERNEL);
- if (!conf->devlist)
+ if (!conf->devlist) {
+ err = -ENOMEM;
goto free_zone;
+ }

/* The first zone must contain all devices, so here we check that
* there is a proper alignment of slots to devices and find them all
--
2.10.1

2016-10-06 08:57:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 04/54] md/raid0: Replace printk() calls by the usage of higher level interfaces

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 13:30:39 +0200

1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt"
so that their information can be used for consistent message output.

2. Prefer usage of some higher level macros over calling "printk" directly
in this software module.

3. Remove prefixes from strings which were passed to some function
and macro calls.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 100 +++++++++++++++++++++++++----------------------------
1 file changed, 47 insertions(+), 53 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 71bd398..3079c3e 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -17,6 +17,8 @@
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

+#define MY_LOG_PREFIX KBUILD_MODNAME ": "
+#define pr_fmt(fmt) MY_LOG_PREFIX fmt
#include <linux/blkdev.h>
#include <linux/seq_file.h>
#include <linux/module.h>
@@ -51,20 +53,20 @@ static void dump_zones(struct mddev *mddev)
char b[BDEVNAME_SIZE];
struct r0conf *conf = mddev->private;
int raid_disks = conf->strip_zone[0].nb_dev;
- printk(KERN_INFO "md: RAID0 configuration for %s - %d zone%s\n",
+ pr_info("configuration for %s - %d zone%s\n",
mdname(mddev),
conf->nr_strip_zones, conf->nr_strip_zones==1?"":"s");
for (j = 0; j < conf->nr_strip_zones; j++) {
- printk(KERN_INFO "md: zone%d=[", j);
+ pr_info("zone%d=[", j);
for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
- printk(KERN_CONT "%s%s", k?"/":"",
- bdevname(conf->devlist[j*raid_disks
- + k]->bdev, b));
- printk(KERN_CONT "]\n");
-
+ pr_cont("%s%s",
+ k ? "/" : "",
+ bdevname(conf->devlist[j * raid_disks + k]
+ ->bdev,
+ b));
+ pr_cont("]\n");
zone_size = conf->strip_zone[j].zone_end - zone_start;
- printk(KERN_INFO " zone-offset=%10lluKB, "
- "device-offset=%10lluKB, size=%10lluKB\n",
+ pr_info(" zone-offset=%10lluKB, device-offset=%10lluKB, size=%10lluKB\n",
(unsigned long long)zone_start>>1,
(unsigned long long)conf->strip_zone[j].dev_start>>1,
(unsigned long long)zone_size>>1);
@@ -88,7 +90,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
if (!conf)
return -ENOMEM;
rdev_for_each(rdev1, mddev) {
- pr_debug("md/raid0:%s: looking at %s\n",
+ pr_debug("%s: looking at %s\n",
mdname(mddev),
bdevname(rdev1->bdev, b));
c = 0;
@@ -102,15 +104,14 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
rdev1->bdev->bd_disk->queue));

rdev_for_each(rdev2, mddev) {
- pr_debug("md/raid0:%s: comparing %s(%llu)"
- " with %s(%llu)\n",
+ pr_debug("%s: comparing %s(%llu) with %s(%llu)\n",
mdname(mddev),
bdevname(rdev1->bdev,b),
(unsigned long long)rdev1->sectors,
bdevname(rdev2->bdev,b2),
(unsigned long long)rdev2->sectors);
if (rdev2 == rdev1) {
- pr_debug("md/raid0:%s: END\n",
+ pr_debug("%s: END\n",
mdname(mddev));
break;
}
@@ -119,30 +120,30 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
* Not unique, don't count it as a new
* group
*/
- pr_debug("md/raid0:%s: EQUAL\n",
+ pr_debug("%s: EQUAL\n",
mdname(mddev));
c = 1;
break;
}
- pr_debug("md/raid0:%s: NOT EQUAL\n",
+ pr_debug("%s: NOT EQUAL\n",
mdname(mddev));
}
if (!c) {
- pr_debug("md/raid0:%s: ==> UNIQUE\n",
+ pr_debug("%s: ==> UNIQUE\n",
mdname(mddev));
conf->nr_strip_zones++;
- pr_debug("md/raid0:%s: %d zones\n",
+ pr_debug("%s: %d zones\n",
mdname(mddev), conf->nr_strip_zones);
}
}
- pr_debug("md/raid0:%s: FINAL %d zones\n",
+ pr_debug("%s: FINAL %d zones\n",
mdname(mddev), conf->nr_strip_zones);
/*
* now since we have the hard sector sizes, we can make sure
* chunk size is a multiple of that sector size
*/
if ((mddev->chunk_sectors << 9) % blksize) {
- printk(KERN_ERR "md/raid0:%s: chunk_size of %d not multiple of block size %d\n",
+ pr_err("%s: chunk_size of %d not multiple of block size %d\n",
mdname(mddev),
mddev->chunk_sectors << 9, blksize);
err = -EINVAL;
@@ -191,19 +192,18 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
}

if (j < 0) {
- printk(KERN_ERR
- "md/raid0:%s: remove inactive devices before converting to RAID0\n",
+ pr_err("%s: remove inactive devices before converting to RAID0\n",
mdname(mddev));
goto free_device_list;
}
if (j >= mddev->raid_disks) {
- printk(KERN_ERR "md/raid0:%s: bad disk number %d - "
- "aborting!\n", mdname(mddev), j);
+ pr_err("%s: bad disk number %d%s",
+ mdname(mddev), j, " - aborting!\n");
goto free_device_list;
}
if (dev[j]) {
- printk(KERN_ERR "md/raid0:%s: multiple devices for %d - "
- "aborting!\n", mdname(mddev), j);
+ pr_err("%s: multiple devices for %d%s",
+ mdname(mddev), j, " - aborting!\n");
goto free_device_list;
}
dev[j] = rdev1;
@@ -213,8 +213,8 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
cnt++;
}
if (cnt != mddev->raid_disks) {
- printk(KERN_ERR "md/raid0:%s: too few disks (%d of %d) - "
- "aborting!\n", mdname(mddev), cnt, mddev->raid_disks);
+ pr_err("%s: too few disks (%d of %d)%s",
+ mdname(mddev), cnt, mddev->raid_disks, " - aborting!\n");
goto free_device_list;
}
zone->nb_dev = cnt;
@@ -229,8 +229,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)

zone = conf->strip_zone + i;
dev = conf->devlist + i * mddev->raid_disks;
-
- pr_debug("md/raid0:%s: zone %d\n", mdname(mddev), i);
+ pr_debug("%s: zone %d\n", mdname(mddev), i);
zone->dev_start = smallest->sectors;
smallest = NULL;
c = 0;
@@ -238,20 +237,19 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
for (j=0; j<cnt; j++) {
rdev = conf->devlist[j];
if (rdev->sectors <= zone->dev_start) {
- pr_debug("md/raid0:%s: checking %s ... nope\n",
+ pr_debug("%s: checking %s ... nope\n",
mdname(mddev),
bdevname(rdev->bdev, b));
continue;
}
- pr_debug("md/raid0:%s: checking %s ..."
- " contained as device %d\n",
+ pr_debug("%s: checking %s ... contained as device %d\n",
mdname(mddev),
bdevname(rdev->bdev, b), c);
dev[c] = rdev;
c++;
if (!smallest || rdev->sectors < smallest->sectors) {
smallest = rdev;
- pr_debug("md/raid0:%s: (%llu) is smallest!.\n",
+ pr_debug("%s: (%llu) is smallest!.\n",
mdname(mddev),
(unsigned long long)rdev->sectors);
}
@@ -259,19 +257,18 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)

zone->nb_dev = c;
sectors = (smallest->sectors - zone->dev_start) * c;
- pr_debug("md/raid0:%s: zone->nb_dev: %d, sectors: %llu\n",
+ pr_debug("%s: zone->nb_dev: %d, sectors: %llu\n",
mdname(mddev),
zone->nb_dev, (unsigned long long)sectors);

curr_zone_end += sectors;
zone->zone_end = curr_zone_end;
-
- pr_debug("md/raid0:%s: current zone start: %llu\n",
+ pr_debug("%s: current zone start: %llu\n",
mdname(mddev),
(unsigned long long)smallest->sectors);
}

- pr_debug("md/raid0:%s: done.\n", mdname(mddev));
+ pr_debug("%s: done.\n", mdname(mddev));
*private_conf = conf;

return 0;
@@ -364,8 +361,7 @@ static int raid0_run(struct mddev *mddev)
int ret;

if (mddev->chunk_sectors == 0) {
- printk(KERN_ERR "md/raid0:%s: chunk size must be set.\n",
- mdname(mddev));
+ pr_err("%s: chunk size must be set.\n", mdname(mddev));
return -EINVAL;
}
if (md_check_no_bitmap(mddev))
@@ -405,10 +401,9 @@ static int raid0_run(struct mddev *mddev)

/* calculate array device size */
md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
-
- printk(KERN_INFO "md/raid0:%s: md_size is %llu sectors.\n",
- mdname(mddev),
- (unsigned long long)mddev->array_sectors);
+ pr_info("%s: md_size is %llu sectors.\n",
+ mdname(mddev),
+ (unsigned long long)mddev->array_sectors);

if (mddev->queue) {
/* calculate the max read-ahead size.
@@ -516,7 +511,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)
struct r0conf *priv_conf;

if (mddev->degraded != 1) {
- printk(KERN_ERR "md/raid0:%s: raid5 must be degraded! Degraded disks: %d\n",
+ pr_err("%s: raid5 must be degraded! Degraded disks: %d\n",
mdname(mddev),
mddev->degraded);
return ERR_PTR(-EINVAL);
@@ -525,7 +520,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)
rdev_for_each(rdev, mddev) {
/* check slot number for a disk */
if (rdev->raid_disk == mddev->raid_disks-1) {
- printk(KERN_ERR "md/raid0:%s: raid5 must have missing parity disk!\n",
+ pr_err("%s: raid5 must have missing parity disk!\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
@@ -556,18 +551,18 @@ static void *raid0_takeover_raid10(struct mddev *mddev)
* - all mirrors must be already degraded
*/
if (mddev->layout != ((1 << 8) + 2)) {
- printk(KERN_ERR "md/raid0:%s:: Raid0 cannot takeover layout: 0x%x\n",
+ pr_err("%s: Raid0 cannot takeover layout: 0x%x\n",
mdname(mddev),
mddev->layout);
return ERR_PTR(-EINVAL);
}
if (mddev->raid_disks & 1) {
- printk(KERN_ERR "md/raid0:%s: Raid0 cannot takeover Raid10 with odd disk number.\n",
+ pr_err("%s: Raid0 cannot takeover Raid10 with odd disk number.\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
if (mddev->degraded != (mddev->raid_disks>>1)) {
- printk(KERN_ERR "md/raid0:%s: All mirrors must be already degraded!\n",
+ pr_err("%s: All mirrors must be already degraded!\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
@@ -595,7 +590,7 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
* - (N - 1) mirror drives must be already faulty
*/
if ((mddev->raid_disks - 1) != mddev->degraded) {
- printk(KERN_ERR "md/raid0:%s: (N - 1) mirrors drives must be already faulty!\n",
+ pr_err("%s: (N - 1) mirrors drives must be already faulty!\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
@@ -638,7 +633,7 @@ static void *raid0_takeover(struct mddev *mddev)
*/

if (mddev->bitmap) {
- printk(KERN_ERR "md/raid0: %s: cannot takeover array with bitmap\n",
+ pr_err("%s: cannot takeover array with bitmap\n",
mdname(mddev));
return ERR_PTR(-EBUSY);
}
@@ -649,7 +644,7 @@ static void *raid0_takeover(struct mddev *mddev)
if (mddev->layout == ALGORITHM_PARITY_N)
return raid0_takeover_raid45(mddev);

- printk(KERN_ERR "md/raid0:%s: Raid can only takeover Raid5 with layout: %d\n",
+ pr_err("%s: Raid can only takeover Raid5 with layout: %d\n",
mdname(mddev), ALGORITHM_PARITY_N);
}

@@ -659,9 +654,8 @@ static void *raid0_takeover(struct mddev *mddev)
if (mddev->level == 1)
return raid0_takeover_raid1(mddev);

- printk(KERN_ERR "Takeover from raid%i to raid0 not supported\n",
+ pr_err("Takeover from raid%i to raid0 not supported\n",
mddev->level);
-
return ERR_PTR(-EINVAL);
}

--
2.10.1

2016-10-06 08:58:26

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 05/54] md/raid0: Move another variable assignment in create_strip_zones()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 13:54:36 +0200

One local variable was set to an error code before a concrete
error situation was detected. Thus move the corresponding assignment
to the end to indicate a software failure there.
Use it finally in four if branches for exception handling.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 3079c3e..0315f1e 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -173,7 +173,6 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
cnt = 0;
smallest = NULL;
dev = conf->devlist;
- err = -EINVAL;
rdev_for_each(rdev1, mddev) {
int j = rdev1->raid_disk;

@@ -194,17 +193,17 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
if (j < 0) {
pr_err("%s: remove inactive devices before converting to RAID0\n",
mdname(mddev));
- goto free_device_list;
+ goto e_inval;
}
if (j >= mddev->raid_disks) {
pr_err("%s: bad disk number %d%s",
mdname(mddev), j, " - aborting!\n");
- goto free_device_list;
+ goto e_inval;
}
if (dev[j]) {
pr_err("%s: multiple devices for %d%s",
mdname(mddev), j, " - aborting!\n");
- goto free_device_list;
+ goto e_inval;
}
dev[j] = rdev1;

@@ -215,7 +214,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
if (cnt != mddev->raid_disks) {
pr_err("%s: too few disks (%d of %d)%s",
mdname(mddev), cnt, mddev->raid_disks, " - aborting!\n");
- goto free_device_list;
+ goto e_inval;
}
zone->nb_dev = cnt;
zone->zone_end = smallest->sectors * cnt;
@@ -280,6 +279,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
kfree(conf);
*private_conf = ERR_PTR(err);
return err;
+e_inval:
+ err = -EINVAL;
+ goto free_device_list;
}

/* Find the zone which holds a particular offset
--
2.10.1

2016-10-06 09:00:54

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 07/54] md/raid0: Move two misplaced braces

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:25:01 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: that open brace { should be on the previous line

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 06cb172..9b76eae 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -222,8 +222,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
curr_zone_end = zone->zone_end;

/* now do the other zones */
- for (i = 1; i < conf->nr_strip_zones; i++)
- {
+ for (i = 1; i < conf->nr_strip_zones; i++) {
int j;

zone = conf->strip_zone + i;
@@ -665,8 +664,7 @@ static void raid0_quiesce(struct mddev *mddev, int state)
{
}

-static struct md_personality raid0_personality=
-{
+static struct md_personality raid0_personality = {
.name = "raid0",
.level = 0,
.owner = THIS_MODULE,
--
2.10.1

2016-10-06 09:02:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 08/54] md/raid0: Delete an unnecessary return statement in raid0_status()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:34:33 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement here.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 9b76eae..1abe1ee 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -503,7 +503,6 @@ static void raid0_make_request(struct mddev *mddev, struct bio *bio)
static void raid0_status(struct seq_file *seq, struct mddev *mddev)
{
seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2);
- return;
}

static void *raid0_takeover_raid45(struct mddev *mddev)
--
2.10.1

2016-10-06 09:03:47

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 09/54] md/raid0: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:48:34 +0200

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 1abe1ee..39d407c 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -55,7 +55,7 @@ static void dump_zones(struct mddev *mddev)
int raid_disks = conf->strip_zone[0].nb_dev;
pr_info("configuration for %s - %d zone%s\n",
mdname(mddev),
- conf->nr_strip_zones, conf->nr_strip_zones==1?"":"s");
+ conf->nr_strip_zones, conf->nr_strip_zones == 1 ? "" : "s");
for (j = 0; j < conf->nr_strip_zones; j++) {
pr_info("zone%d=[", j);
for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
@@ -106,9 +106,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
rdev_for_each(rdev2, mddev) {
pr_debug("%s: comparing %s(%llu) with %s(%llu)\n",
mdname(mddev),
- bdevname(rdev1->bdev,b),
+ bdevname(rdev1->bdev, b),
(unsigned long long)rdev1->sectors,
- bdevname(rdev2->bdev,b2),
+ bdevname(rdev2->bdev, b2),
(unsigned long long)rdev2->sectors);
if (rdev2 == rdev1) {
pr_debug("%s: END\n",
@@ -232,7 +232,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
smallest = NULL;
c = 0;

- for (j=0; j<cnt; j++) {
+ for (j = 0; j < cnt; j++) {
rdev = conf->devlist[j];
if (rdev->sectors <= zone->dev_start) {
pr_debug("%s: checking %s ... nope\n",
@@ -418,8 +418,8 @@ static int raid0_run(struct mddev *mddev)
*/
int stripe = mddev->raid_disks *
(mddev->chunk_sectors << 9) / PAGE_SIZE;
- if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
- mddev->queue->backing_dev_info.ra_pages = 2* stripe;
+ if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
+ mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
}

dump_zones(mddev);
--
2.10.1

2016-10-06 09:05:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 10/54] md/raid1: Use kcalloc() in alloc_behind_pages()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:01:04 +0200

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 1961d82..d2759f8 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -955,8 +955,7 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio)
{
int i;
struct bio_vec *bvec;
- struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec),
- GFP_NOIO);
+ struct bio_vec *bvecs = kcalloc(bio->bi_vcnt, sizeof(*bvecs), GFP_NOIO);
if (unlikely(!bvecs))
return;

--
2.10.1

2016-10-06 09:06:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 06/54] md/raid0: Delete four unwanted spaces behind function names

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 14:21:21 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: space prohibited between function name and open parenthesis '('

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 0315f1e..06cb172 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -680,14 +680,14 @@ static struct md_personality raid0_personality=
.congested = raid0_congested,
};

-static int __init raid0_init (void)
+static int __init raid0_init(void)
{
- return register_md_personality (&raid0_personality);
+ return register_md_personality(&raid0_personality);
}

-static void raid0_exit (void)
+static void raid0_exit(void)
{
- unregister_md_personality (&raid0_personality);
+ unregister_md_personality(&raid0_personality);
}

module_init(raid0_init);
--
2.10.1

2016-10-06 09:07:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 11/54] md/raid1: Use kcalloc() in raid1_reshape()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:17:13 +0200

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kcalloc".

* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index d2759f8..e75ae87 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -3081,8 +3081,8 @@ static int raid1_reshape(struct mddev *mddev)
kfree(newpoolinfo);
return -ENOMEM;
}
- newmirrors = kzalloc(sizeof(struct raid1_info) * raid_disks * 2,
- GFP_KERNEL);
+
+ newmirrors = kcalloc(raid_disks * 2, sizeof(*newmirrors), GFP_KERNEL);
if (!newmirrors) {
kfree(newpoolinfo);
mempool_destroy(newpool);
--
2.10.1

2016-10-06 09:08:22

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 12/54] md/raid1: Use kcalloc() in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:30:28 +0200

* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kcalloc".

* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index e75ae87..5969711 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2781,9 +2781,9 @@ static struct r1conf *setup_conf(struct mddev *mddev)
if (!conf)
goto abort;

- conf->mirrors = kzalloc(sizeof(struct raid1_info)
- * mddev->raid_disks * 2,
- GFP_KERNEL);
+ conf->mirrors = kcalloc(mddev->raid_disks * 2,
+ sizeof(*conf->mirrors),
+ GFP_KERNEL);
if (!conf->mirrors)
goto abort;

--
2.10.1

2016-10-06 09:10:09

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 13/54] md/raid1: Return directly after a failed kzalloc() in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 15:56:41 +0200

* Return directly after a call of the function "kzalloc" failed
at the beginning.

* Delete a repeated check for the local variable "conf"
which became unnecessary with this refactoring.

* Reorder two calls for the function "kfree" at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 5969711..74346f5 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2779,7 +2779,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)

conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL);
if (!conf)
- goto abort;
+ return ERR_PTR(-ENOMEM);

conf->mirrors = kcalloc(mddev->raid_disks * 2,
sizeof(*conf->mirrors),
@@ -2880,13 +2880,11 @@ static struct r1conf *setup_conf(struct mddev *mddev)
return conf;

abort:
- if (conf) {
- mempool_destroy(conf->r1bio_pool);
- kfree(conf->mirrors);
- safe_put_page(conf->tmppage);
- kfree(conf->poolinfo);
- kfree(conf);
- }
+ mempool_destroy(conf->r1bio_pool);
+ kfree(conf->poolinfo);
+ safe_put_page(conf->tmppage);
+ kfree(conf->mirrors);
+ kfree(conf);
return ERR_PTR(err);
}

--
2.10.1

2016-10-06 09:11:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 14/54] md/raid1: Move assignments for the variable "err" in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 17:34:10 +0200

One local variable was set to an error code in a few cases before
a concrete error situation was detected. Thus move the corresponding
assignments into if branches to indicate a software failure there.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 74346f5..4d2fcbc 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2775,7 +2775,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
int i;
struct raid1_info *disk;
struct md_rdev *rdev;
- int err = -ENOMEM;
+ int err;

conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL);
if (!conf)
@@ -2784,26 +2784,33 @@ static struct r1conf *setup_conf(struct mddev *mddev)
conf->mirrors = kcalloc(mddev->raid_disks * 2,
sizeof(*conf->mirrors),
GFP_KERNEL);
- if (!conf->mirrors)
+ if (!conf->mirrors) {
+ err = -ENOMEM;
goto abort;
+ }

conf->tmppage = alloc_page(GFP_KERNEL);
- if (!conf->tmppage)
+ if (!conf->tmppage) {
+ err = -ENOMEM;
goto abort;
+ }

conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
- if (!conf->poolinfo)
+ if (!conf->poolinfo) {
+ err = -ENOMEM;
goto abort;
+ }
+
conf->poolinfo->raid_disks = mddev->raid_disks * 2;
conf->r1bio_pool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
r1bio_pool_free,
conf->poolinfo);
- if (!conf->r1bio_pool)
+ if (!conf->r1bio_pool) {
+ err = -ENOMEM;
goto abort;
+ }

conf->poolinfo->mddev = mddev;
-
- err = -EINVAL;
spin_lock_init(&conf->device_lock);
rdev_for_each(rdev, mddev) {
struct request_queue *q;
@@ -2816,8 +2823,11 @@ static struct r1conf *setup_conf(struct mddev *mddev)
else
disk = conf->mirrors + disk_idx;

- if (disk->rdev)
+ if (disk->rdev) {
+ err = -EINVAL;
goto abort;
+ }
+
disk->rdev = rdev;
q = bdev_get_queue(rdev->bdev);

@@ -2838,8 +2848,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)

conf->start_next_window = MaxSector;
conf->current_window_requests = conf->next_window_requests = 0;
-
- err = -EIO;
for (i = 0; i < conf->raid_disks * 2; i++) {

disk = conf->mirrors + i;
@@ -2854,9 +2862,13 @@ static struct r1conf *setup_conf(struct mddev *mddev)
disk->rdev =
disk[conf->raid_disks].rdev;
disk[conf->raid_disks].rdev = NULL;
- } else if (!test_bit(In_sync, &disk->rdev->flags))
- /* Original is not in_sync - bad */
- goto abort;
+ } else {
+ if (!test_bit(In_sync, &disk->rdev->flags)) {
+ /* Original is not in_sync - bad */
+ err = -EIO;
+ goto abort;
+ }
+ }
}

if (!disk->rdev ||
@@ -2868,12 +2880,12 @@ static struct r1conf *setup_conf(struct mddev *mddev)
}
}

- err = -ENOMEM;
conf->thread = md_register_thread(raid1d, mddev, "raid1");
if (!conf->thread) {
printk(KERN_ERR
"md/raid1:%s: couldn't allocate thread\n",
mdname(mddev));
+ err = -ENOMEM;
goto abort;
}

--
2.10.1

2016-10-06 09:12:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 15/54] md/raid1: Less function calls in setup_conf() after error detection

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:01:02 +0200

Resource release functions were called in up to four cases
by the setup_conf() function during error handling even if
the passed data structure members contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 4d2fcbc..7dc45ba 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2786,19 +2786,19 @@ static struct r1conf *setup_conf(struct mddev *mddev)
GFP_KERNEL);
if (!conf->mirrors) {
err = -ENOMEM;
- goto abort;
+ goto free_conf;
}

conf->tmppage = alloc_page(GFP_KERNEL);
if (!conf->tmppage) {
err = -ENOMEM;
- goto abort;
+ goto free_mirrors;
}

conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
if (!conf->poolinfo) {
err = -ENOMEM;
- goto abort;
+ goto put_page;
}

conf->poolinfo->raid_disks = mddev->raid_disks * 2;
@@ -2807,7 +2807,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
conf->poolinfo);
if (!conf->r1bio_pool) {
err = -ENOMEM;
- goto abort;
+ goto free_poolinfo;
}

conf->poolinfo->mddev = mddev;
@@ -2825,7 +2825,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)

if (disk->rdev) {
err = -EINVAL;
- goto abort;
+ goto destroy_pool;
}

disk->rdev = rdev;
@@ -2866,7 +2866,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
if (!test_bit(In_sync, &disk->rdev->flags)) {
/* Original is not in_sync - bad */
err = -EIO;
- goto abort;
+ goto destroy_pool;
}
}
}
@@ -2886,16 +2886,19 @@ static struct r1conf *setup_conf(struct mddev *mddev)
"md/raid1:%s: couldn't allocate thread\n",
mdname(mddev));
err = -ENOMEM;
- goto abort;
+ goto destroy_pool;
}

return conf;
-
- abort:
+destroy_pool:
mempool_destroy(conf->r1bio_pool);
+free_poolinfo:
kfree(conf->poolinfo);
+put_page:
safe_put_page(conf->tmppage);
+free_mirrors:
kfree(conf->mirrors);
+free_conf:
kfree(conf);
return ERR_PTR(err);
}
--
2.10.1

2016-10-06 09:13:59

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 16/54] md/raid1: Delete an error message for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:15:20 +0200

Omit an extra message for a memory allocation failure in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 7dc45ba..15b9652 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2882,9 +2882,6 @@ static struct r1conf *setup_conf(struct mddev *mddev)

conf->thread = md_register_thread(raid1d, mddev, "raid1");
if (!conf->thread) {
- printk(KERN_ERR
- "md/raid1:%s: couldn't allocate thread\n",
- mdname(mddev));
err = -ENOMEM;
goto destroy_pool;
}
--
2.10.1

2016-10-06 09:15:29

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 17/54] md/raid1: Move a brace for a designated initialiser

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:25:05 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: that open brace { should be on the previous line

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 15b9652..958bf41 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -3176,8 +3176,7 @@ static void *raid1_takeover(struct mddev *mddev)
return ERR_PTR(-EINVAL);
}

-static struct md_personality raid1_personality =
-{
+static struct md_personality raid1_personality = {
.name = "raid1",
.level = 1,
.owner = THIS_MODULE,
--
2.10.1

2016-10-06 09:16:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 18/54] md/raid1: Adjust 12 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 18:55:42 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 958bf41..3a1194e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -474,7 +474,7 @@ static void raid1_end_write_request(struct bio *bio)
}
}
}
- if (r1_bio->bios[mirror] == NULL)
+ if (!r1_bio->bios[mirror])
rdev_dec_pending(rdev, conf->mddev);

/*
@@ -549,7 +549,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect

rdev = rcu_dereference(conf->mirrors[disk].rdev);
if (r1_bio->bios[disk] == IO_BLOCKED
- || rdev == NULL
+ || !rdev
|| test_bit(Faulty, &rdev->flags))
continue;
if (!test_bit(In_sync, &rdev->flags) &&
@@ -1582,7 +1582,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
*/
if (rdev->saved_raid_disk >= 0 &&
rdev->saved_raid_disk >= first &&
- conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
+ !conf->mirrors[rdev->saved_raid_disk].rdev)
first = last = rdev->saved_raid_disk;

for (mirror = first; mirror <= last; mirror++) {
@@ -1605,7 +1605,7 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
break;
}
if (test_bit(WantReplacement, &p->rdev->flags) &&
- p[conf->raid_disks].rdev == NULL) {
+ !p[conf->raid_disks].rdev) {
/* Add this device as a replacement */
clear_bit(In_sync, &rdev->flags);
set_bit(Replacement, &rdev->flags);
@@ -2002,7 +2002,7 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
atomic_set(&r1_bio->remaining, 1);
for (i = 0; i < disks ; i++) {
wbio = r1_bio->bios[i];
- if (wbio->bi_end_io == NULL ||
+ if (!wbio->bi_end_io ||
(wbio->bi_end_io == end_sync_read &&
(i == r1_bio->read_disk ||
!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))))
@@ -2220,7 +2220,7 @@ static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio
for (m = 0; m < conf->raid_disks * 2 ; m++) {
struct md_rdev *rdev = conf->mirrors[m].rdev;
struct bio *bio = r1_bio->bios[m];
- if (bio->bi_end_io == NULL)
+ if (!bio->bi_end_io)
continue;
if (!bio->bi_error &&
test_bit(R1BIO_MadeGood, &r1_bio->state)) {
@@ -2247,7 +2247,7 @@ static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio)
r1_bio->sector,
r1_bio->sectors, 0);
rdev_dec_pending(rdev, conf->mddev);
- } else if (r1_bio->bios[m] != NULL) {
+ } else if (r1_bio->bios[m]) {
/* This drive got a write error. We need to
* narrow down and record precise write
* errors.
@@ -2509,7 +2509,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
return 0;
}

- if (mddev->bitmap == NULL &&
+ if (!mddev->bitmap &&
mddev->recovery_cp == MaxSector &&
!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) &&
conf->fullsync == 0) {
@@ -2564,7 +2564,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
bio_reset(bio);

rdev = rcu_dereference(conf->mirrors[i].rdev);
- if (rdev == NULL ||
+ if (!rdev ||
test_bit(Faulty, &rdev->flags)) {
if (i < conf->raid_disks)
still_degraded = 1;
@@ -2710,7 +2710,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
while (i > 0) {
i--;
bio = r1_bio->bios[i];
- if (bio->bi_end_io==NULL)
+ if (!bio->bi_end_io)
continue;
/* remove last page from this bio */
bio->bi_vcnt--;
@@ -2924,7 +2924,7 @@ static int raid1_run(struct mddev *mddev)
* bookkeeping area. [whatever we allocate in run(),
* should be freed in raid1_free()]
*/
- if (mddev->private == NULL)
+ if (!mddev->private)
conf = setup_conf(mddev);
else
conf = mddev->private;
@@ -2946,7 +2946,7 @@ static int raid1_run(struct mddev *mddev)

mddev->degraded = 0;
for (i=0; i < conf->raid_disks; i++)
- if (conf->mirrors[i].rdev == NULL ||
+ if (!conf->mirrors[i].rdev ||
!test_bit(In_sync, &conf->mirrors[i].rdev->flags) ||
test_bit(Faulty, &conf->mirrors[i].rdev->flags))
mddev->degraded++;
--
2.10.1

2016-10-06 09:17:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 19/54] md/raid1: Replace printk() calls by the usage of higher level interfaces

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 20:30:07 +0200

1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt"
so that their information can be used for consistent message output.

2. Prefer usage of some higher level macros over calling "printk" directly
in this software module.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 91 ++++++++++++++++++++++++++----------------------------
1 file changed, 43 insertions(+), 48 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3a1194e..9754b7d 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -31,6 +31,8 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

+#define MY_LOG_PREFIX KBUILD_MODNAME ": "
+#define pr_fmt(fmt) MY_LOG_PREFIX fmt
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/blkdev.h>
@@ -347,13 +349,11 @@ static void raid1_end_read_request(struct bio *bio)
* oops, read error:
*/
char b[BDEVNAME_SIZE];
- printk_ratelimited(
- KERN_ERR "md/raid1:%s: %s: "
- "rescheduling sector %llu\n",
- mdname(conf->mddev),
- bdevname(rdev->bdev,
- b),
- (unsigned long long)r1_bio->sector);
+
+ pr_err_ratelimited("%s: %s: rescheduling sector %llu\n",
+ mdname(conf->mddev),
+ bdevname(rdev->bdev, b),
+ (unsigned long long)r1_bio->sector);
set_bit(R1BIO_ReadError, &r1_bio->state);
reschedule_retry(r1_bio);
/* don't drop the reference on read_disk yet */
@@ -1457,34 +1457,34 @@ static void raid1_error(struct mddev *mddev, struct md_rdev *rdev)
set_bit(MD_RECOVERY_INTR, &mddev->recovery);
set_mask_bits(&mddev->flags, 0,
BIT(MD_CHANGE_DEVS) | BIT(MD_CHANGE_PENDING));
- printk(KERN_ALERT
- "md/raid1:%s: Disk failure on %s, disabling device.\n"
- "md/raid1:%s: Operation continuing on %d devices.\n",
- mdname(mddev), bdevname(rdev->bdev, b),
- mdname(mddev), conf->raid_disks - mddev->degraded);
+ pr_alert("%s: Disk failure on %s, disabling device.\n"
+ MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n",
+ mdname(mddev), bdevname(rdev->bdev, b),
+ mdname(mddev), conf->raid_disks - mddev->degraded);
}

static void print_conf(struct r1conf *conf)
{
int i;

- printk(KERN_DEBUG "RAID1 conf printout:\n");
+ pr_debug("conf printout:\n");
if (!conf) {
- printk(KERN_DEBUG "(!conf)\n");
+ pr_debug("(!conf)\n");
return;
}
- printk(KERN_DEBUG " --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded,
- conf->raid_disks);
+ pr_debug("--- wd:%d rd:%d\n",
+ conf->raid_disks - conf->mddev->degraded,
+ conf->raid_disks);

rcu_read_lock();
for (i = 0; i < conf->raid_disks; i++) {
char b[BDEVNAME_SIZE];
struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev);
if (rdev)
- printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n",
- i, !test_bit(In_sync, &rdev->flags),
- !test_bit(Faulty, &rdev->flags),
- bdevname(rdev->bdev,b));
+ pr_debug("disk %d, wo:%d, o:%d, dev:%s\n",
+ i, !test_bit(In_sync, &rdev->flags),
+ !test_bit(Faulty, &rdev->flags),
+ bdevname(rdev->bdev, b));
}
rcu_read_unlock();
}
@@ -1821,11 +1821,10 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
* work just disable and interrupt the recovery.
* Don't fail devices as that won't really help.
*/
- printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O read error"
- " for block %llu\n",
- mdname(mddev),
- bdevname(bio->bi_bdev, b),
- (unsigned long long)r1_bio->sector);
+ pr_alert("%s: %s: unrecoverable I/O read error for block %llu\n",
+ mdname(mddev),
+ bdevname(bio->bi_bdev, b),
+ (unsigned long long)r1_bio->sector);
for (d = 0; d < conf->raid_disks * 2; d++) {
rdev = conf->mirrors[d].rdev;
if (!rdev || test_bit(Faulty, &rdev->flags))
@@ -2118,13 +2117,13 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
if (r1_sync_page_io(rdev, sect, s,
conf->tmppage, READ)) {
atomic_add(s, &rdev->corrected_errors);
- printk(KERN_INFO
- "md/raid1:%s: read error corrected "
- "(%d sectors at %llu on %s)\n",
- mdname(mddev), s,
- (unsigned long long)(sect +
- rdev->data_offset),
- bdevname(rdev->bdev, b));
+ pr_info("%s: read error corrected "
+ "(%d sectors at %llu on %s)\n",
+ mdname(mddev),
+ s,
+ (unsigned long long)(sect +
+ rdev->data_offset),
+ bdevname(rdev->bdev, b));
}
rdev_dec_pending(rdev, mddev);
} else
@@ -2307,9 +2306,8 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
read_more:
disk = read_balance(conf, r1_bio, &max_sectors);
if (disk == -1) {
- printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O"
- " read error for block %llu\n",
- mdname(mddev), b, (unsigned long long)r1_bio->sector);
+ pr_alert("%s: %s: unrecoverable I/O read error for block %llu\n",
+ mdname(mddev), b, (unsigned long long)r1_bio->sector);
raid_end_bio_io(r1_bio);
} else {
const unsigned long do_sync
@@ -2325,8 +2323,7 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
max_sectors);
r1_bio->bios[r1_bio->read_disk] = bio;
rdev = conf->mirrors[disk].rdev;
- printk_ratelimited(KERN_ERR
- "md/raid1:%s: redirecting sector %llu"
+ pr_err_ratelimited("%s: redirecting sector %llu"
" to other mirror: %s\n",
mdname(mddev),
(unsigned long long)r1_bio->sector,
@@ -2910,12 +2907,12 @@ static int raid1_run(struct mddev *mddev)
bool discard_supported = false;

if (mddev->level != 1) {
- printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n",
+ pr_err("%s: raid level not set to mirroring (%d)\n",
mdname(mddev), mddev->level);
return -EIO;
}
if (mddev->reshape_position != MaxSector) {
- printk(KERN_ERR "md/raid1:%s: reshape_position set but not supported\n",
+ pr_err("%s: reshape_position set but not supported\n",
mdname(mddev));
return -EIO;
}
@@ -2955,12 +2952,11 @@ static int raid1_run(struct mddev *mddev)
mddev->recovery_cp = MaxSector;

if (mddev->recovery_cp != MaxSector)
- printk(KERN_NOTICE "md/raid1:%s: not clean"
- " -- starting background reconstruction\n",
- mdname(mddev));
- printk(KERN_INFO
- "md/raid1:%s: active with %d out of %d mirrors\n",
- mdname(mddev), mddev->raid_disks - mddev->degraded,
+ pr_notice("%s: not clean -- starting background reconstruction\n",
+ mdname(mddev));
+ pr_info("%s: active with %d out of %d mirrors\n",
+ mdname(mddev),
+ mddev->raid_disks - mddev->degraded,
mddev->raid_disks);

/*
@@ -3112,9 +3108,8 @@ static int raid1_reshape(struct mddev *mddev)
rdev->raid_disk = d2;
sysfs_unlink_rdev(mddev, rdev);
if (sysfs_link_rdev(mddev, rdev))
- printk(KERN_WARNING
- "md/raid1:%s: cannot register rd%d\n",
- mdname(mddev), rdev->raid_disk);
+ pr_warn("%s: cannot register rd%d\n",
+ mdname(mddev), rdev->raid_disk);
}
if (rdev)
newmirrors[d2++].rdev = rdev;
--
2.10.1

2016-10-06 09:18:50

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 20/54] md/raid1: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 20:42:25 +0200

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 62 ++++++++++++++++++++++++++++--------------------------
1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 9754b7d..3a03d19 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -136,8 +136,8 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
}
/* If not user-requests, copy the page pointers to all bios */
if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) {
- for (i=0; i<RESYNC_PAGES ; i++)
- for (j=1; j<pi->raid_disks; j++)
+ for (i = 0; i < RESYNC_PAGES ; i++)
+ for (j = 1; j < pi->raid_disks; j++)
r1_bio->bios[j]->bi_io_vec[i].bv_page =
r1_bio->bios[0]->bi_io_vec[i].bv_page;
}
@@ -160,7 +160,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
static void r1buf_pool_free(void *__r1_bio, void *data)
{
struct pool_info *pi = data;
- int i,j;
+ int i, j;
struct r1bio *r1bio = __r1_bio;

for (i = 0; i < RESYNC_PAGES; i++)
@@ -170,7 +170,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data)
r1bio->bios[0]->bi_io_vec[i].bv_page)
safe_put_page(r1bio->bios[j]->bi_io_vec[i].bv_page);
}
- for (i=0 ; i < pi->raid_disks; i++)
+ for (i = 0 ; i < pi->raid_disks; i++)
bio_put(r1bio->bios[i]);

r1bio_pool_free(r1bio, data);
@@ -1785,7 +1785,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
int sectors = r1_bio->sectors;
int idx = 0;

- while(sectors) {
+ while (sectors) {
int s = sectors;
int d = r1_bio->read_disk;
int success = 0;
@@ -2040,7 +2040,8 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
sector_t sect, int sectors)
{
struct mddev *mddev = conf->mddev;
- while(sectors) {
+
+ while (sectors) {
int s = sectors;
int d = read_disk;
int success = 0;
@@ -2087,7 +2088,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
/* write it back and re-read */
start = d;
while (d != read_disk) {
- if (d==0)
+ if (d == 0)
d = conf->raid_disks * 2;
d--;
rcu_read_lock();
@@ -2105,7 +2106,8 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
d = start;
while (d != read_disk) {
char b[BDEVNAME_SIZE];
- if (d==0)
+
+ if (d == 0)
d = conf->raid_disks * 2;
d--;
rcu_read_lock();
@@ -2942,7 +2944,7 @@ static int raid1_run(struct mddev *mddev)
}

mddev->degraded = 0;
- for (i=0; i < conf->raid_disks; i++)
+ for (i = 0; i < conf->raid_disks; i++)
if (!conf->mirrors[i].rdev ||
!test_bit(In_sync, &conf->mirrors[i].rdev->flags) ||
test_bit(Faulty, &conf->mirrors[i].rdev->flags))
@@ -3067,8 +3069,8 @@ static int raid1_reshape(struct mddev *mddev)
raid_disks = mddev->raid_disks + mddev->delta_disks;

if (raid_disks < conf->raid_disks) {
- cnt=0;
- for (d= 0; d < conf->raid_disks; d++)
+ cnt = 0;
+ for (d = 0; d < conf->raid_disks; d++)
if (conf->mirrors[d].rdev)
cnt++;
if (cnt > raid_disks)
@@ -3139,7 +3141,7 @@ static void raid1_quiesce(struct mddev *mddev, int state)
{
struct r1conf *conf = mddev->private;

- switch(state) {
+ switch (state) {
case 2: /* wake for suspend */
wake_up(&conf->wait_barrier);
break;
@@ -3172,24 +3174,24 @@ static void *raid1_takeover(struct mddev *mddev)
}

static struct md_personality raid1_personality = {
- .name = "raid1",
- .level = 1,
- .owner = THIS_MODULE,
- .make_request = raid1_make_request,
- .run = raid1_run,
- .free = raid1_free,
- .status = raid1_status,
- .error_handler = raid1_error,
- .hot_add_disk = raid1_add_disk,
- .hot_remove_disk= raid1_remove_disk,
- .spare_active = raid1_spare_active,
- .sync_request = raid1_sync_request,
- .resize = raid1_resize,
- .size = raid1_size,
- .check_reshape = raid1_reshape,
- .quiesce = raid1_quiesce,
- .takeover = raid1_takeover,
- .congested = raid1_congested,
+ .name = "raid1",
+ .level = 1,
+ .owner = THIS_MODULE,
+ .make_request = raid1_make_request,
+ .run = raid1_run,
+ .free = raid1_free,
+ .status = raid1_status,
+ .error_handler = raid1_error,
+ .hot_add_disk = raid1_add_disk,
+ .hot_remove_disk = raid1_remove_disk,
+ .spare_active = raid1_spare_active,
+ .sync_request = raid1_sync_request,
+ .resize = raid1_resize,
+ .size = raid1_size,
+ .check_reshape = raid1_reshape,
+ .quiesce = raid1_quiesce,
+ .takeover = raid1_takeover,
+ .congested = raid1_congested,
};

static int __init raid_init(void)
--
2.10.1

2016-10-06 09:20:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 21/54] md/raid1: Delete three unwanted spaces behind asterisks

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:01:34 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: "foo * bar" should be "foo *bar"

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3a03d19..fc9d600 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -72,7 +72,7 @@ static void allow_barrier(struct r1conf *conf, sector_t start_next_window,
sector_t bi_sector);
static void lower_barrier(struct r1conf *conf);

-static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
+static void *r1bio_pool_alloc(gfp_t gfp_flags, void *data)
{
struct pool_info *pi = data;
int size = offsetof(struct r1bio, bios[pi->raid_disks]);
@@ -96,7 +96,7 @@ static void r1bio_pool_free(void *r1_bio, void *data)
#define CLUSTER_RESYNC_WINDOW_SECTORS (CLUSTER_RESYNC_WINDOW >> 9)
#define NEXT_NORMALIO_DISTANCE (3 * RESYNC_WINDOW_SECTORS)

-static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
+static void *r1buf_pool_alloc(gfp_t gfp_flags, void *data)
{
struct pool_info *pi = data;
struct r1bio *r1_bio;
@@ -1027,7 +1027,7 @@ static void raid1_unplug(struct blk_plug_cb *cb, bool from_schedule)
kfree(plug);
}

-static void raid1_make_request(struct mddev *mddev, struct bio * bio)
+static void raid1_make_request(struct mddev *mddev, struct bio *bio)
{
struct r1conf *conf = mddev->private;
struct raid1_info *mirror;
--
2.10.1

2016-10-06 09:21:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 22/54] md/raid1: Delete three unwanted spaces before increment operators

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:10:37 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: space prohibited before that '++' (ctx:WxO)

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index fc9d600..95f6098 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -220,7 +220,7 @@ static void reschedule_retry(struct r1bio *r1_bio)

spin_lock_irqsave(&conf->device_lock, flags);
list_add(&r1_bio->retry_list, &conf->retry_list);
- conf->nr_queued ++;
+ conf->nr_queued++;
spin_unlock_irqrestore(&conf->device_lock, flags);

wake_up(&conf->wait_barrier);
@@ -1878,7 +1878,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
}
sectors -= s;
sect += s;
- idx ++;
+ idx++;
}
set_bit(R1BIO_Uptodate, &r1_bio->state);
bio->bi_error = 0;
@@ -2570,7 +2570,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
} else if (!test_bit(In_sync, &rdev->flags)) {
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
bio->bi_end_io = end_sync_write;
- write_targets ++;
+ write_targets++;
} else {
/* may need to read from here */
sector_t first_bad = MaxSector;
--
2.10.1

2016-10-06 09:22:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 23/54] md/raid1: Replace a seq_printf() call by seq_puts() in raid1_status()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:16:13 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 95f6098..ec6aafb 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1417,7 +1417,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev)
rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf(seq, "]");
+ seq_puts(seq, "]");
}

static void raid1_error(struct mddev *mddev, struct md_rdev *rdev)
--
2.10.1

2016-10-06 09:23:07

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 21:46:18 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index ec6aafb..5e1a427 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2776,7 +2776,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
struct md_rdev *rdev;
int err;

- conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL);
+ conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
return ERR_PTR(-ENOMEM);

--
2.10.1

2016-10-06 09:23:45

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 01/54] md/raid0: Use kcalloc() in create_strip_zones()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 10:10:52 +0200

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid0.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 258986a..50e8a63 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -150,12 +150,13 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
}

err = -ENOMEM;
- conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
- conf->nr_strip_zones, GFP_KERNEL);
+ conf->strip_zone = kcalloc(conf->nr_strip_zones,
+ sizeof(*conf->strip_zone),
+ GFP_KERNEL);
if (!conf->strip_zone)
goto abort;
- conf->devlist = kzalloc(sizeof(struct md_rdev*)*
- conf->nr_strip_zones*mddev->raid_disks,
+ conf->devlist = kcalloc(conf->nr_strip_zones * mddev->raid_disks,
+ sizeof(*conf->devlist),
GFP_KERNEL);
if (!conf->devlist)
goto abort;
--
2.10.1

2016-10-06 09:24:48

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 25/54] md/raid5: Use kcalloc() in three functions

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:30:12 +0200

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

* Delete the local variable "size" which became unnecessary with
this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 92ac251..9a43006 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2243,7 +2243,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
* is completely stalled, so now is a good time to resize
* conf->disks and the scribble region
*/
- ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO);
+ ndisks = kcalloc(newsize, sizeof(*ndisks), GFP_NOIO);
if (ndisks) {
for (i=0; i<conf->raid_disks; i++)
ndisks[i] = conf->disks[i];
@@ -6255,7 +6255,6 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,
struct r5worker_group **worker_groups)
{
int i, j, k;
- ssize_t size;
struct r5worker *workers;

*worker_cnt_per_group = cnt;
@@ -6265,10 +6264,8 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,
return 0;
}
*group_cnt = num_possible_nodes();
- size = sizeof(struct r5worker) * cnt;
- workers = kzalloc(size * *group_cnt, GFP_NOIO);
- *worker_groups = kzalloc(sizeof(struct r5worker_group) *
- *group_cnt, GFP_NOIO);
+ workers = kcalloc(cnt * *group_cnt, sizeof(*workers), GFP_NOIO);
+ *worker_groups = kcalloc(*group_cnt, sizeof(**worker_groups), GFP_NOIO);
if (!*worker_groups || !workers) {
kfree(workers);
kfree(*worker_groups);
@@ -6519,9 +6516,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
else
conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks;
max_disks = max(conf->raid_disks, conf->previous_raid_disks);
-
- conf->disks = kzalloc(max_disks * sizeof(struct disk_info),
- GFP_KERNEL);
+ conf->disks = kcalloc(max_disks, sizeof(*conf->disks), GFP_KERNEL);
if (!conf->disks)
goto abort;

--
2.10.1

2016-10-06 09:25:28

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 26/54] md/raid5: Improve another size determination in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:35:06 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 9a43006..562138f 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6481,7 +6481,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
return ERR_PTR(-EINVAL);
}

- conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL);
+ conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (conf == NULL)
goto abort;
/* Don't enable multi-threading by default*/
--
2.10.1

2016-10-06 09:26:41

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 27/54] md/raid5: Return directly after a failed kzalloc() in setup_conf()

From: Markus Elfring <[email protected]>
Date: Tue, 4 Oct 2016 22:44:59 +0200

* Return directly after a call of the function "kzalloc" failed
at the beginning.

* Delete a repeated check for the local variable "conf"
which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 562138f..17f50a6 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6482,8 +6482,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
}

conf = kzalloc(sizeof(*conf), GFP_KERNEL);
- if (conf == NULL)
- goto abort;
+ if (!conf)
+ return ERR_PTR(-ENOMEM);
/* Don't enable multi-threading by default*/
if (!alloc_thread_groups(conf, 0, &group_cnt, &worker_cnt_per_group,
&new_group)) {
@@ -6646,11 +6646,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
return conf;

abort:
- if (conf) {
- free_conf(conf);
- return ERR_PTR(-EIO);
- } else
- return ERR_PTR(-ENOMEM);
+ free_conf(conf);
+ return ERR_PTR(-EIO);
}

static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded)
--
2.10.1

2016-10-06 09:28:48

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 28/54] md/raid5: Rename a jump label in setup_conf()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 08:18:38 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 17f50a6..b624ba6 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6490,8 +6490,10 @@ static struct r5conf *setup_conf(struct mddev *mddev)
conf->group_cnt = group_cnt;
conf->worker_cnt_per_group = worker_cnt_per_group;
conf->worker_groups = new_group;
- } else
- goto abort;
+ } else {
+ goto free_conf;
+ }
+
spin_lock_init(&conf->device_lock);
seqcount_init(&conf->gen_lock);
mutex_init(&conf->cache_size_mutex);
@@ -6518,12 +6520,12 @@ static struct r5conf *setup_conf(struct mddev *mddev)
max_disks = max(conf->raid_disks, conf->previous_raid_disks);
conf->disks = kcalloc(max_disks, sizeof(*conf->disks), GFP_KERNEL);
if (!conf->disks)
- goto abort;
+ goto free_conf;

conf->mddev = mddev;

if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
- goto abort;
+ goto free_conf;

/* We init hash_locks[0] separately to that it can be used
* as the reference lock in the spin_lock_nest_lock() call
@@ -6543,7 +6545,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
conf->level = mddev->new_level;
conf->chunk_sectors = mddev->new_chunk_sectors;
if (raid5_alloc_percpu(conf) != 0)
- goto abort;
+ goto free_conf;

pr_debug("raid456: run(%s) called.\n", mdname(mddev));

@@ -6556,11 +6558,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)

if (test_bit(Replacement, &rdev->flags)) {
if (disk->replacement)
- goto abort;
+ goto free_conf;
disk->replacement = rdev;
} else {
if (disk->rdev)
- goto abort;
+ goto free_conf;
disk->rdev = rdev;
}

@@ -6613,7 +6615,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
printk(KERN_ERR
"md/raid:%s: couldn't allocate %dkB for buffers\n",
mdname(mddev), memory);
- goto abort;
+ goto free_conf;
} else
printk(KERN_INFO "md/raid:%s: allocated %dkB\n",
mdname(mddev), memory);
@@ -6631,7 +6633,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
printk(KERN_ERR
"md/raid:%s: couldn't register shrinker.\n",
mdname(mddev));
- goto abort;
+ goto free_conf;
}

sprintf(pers_name, "raid%d", mddev->new_level);
@@ -6640,12 +6642,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)
printk(KERN_ERR
"md/raid:%s: couldn't allocate thread.\n",
mdname(mddev));
- goto abort;
+ goto free_conf;
}

return conf;
-
- abort:
+free_conf:
free_conf(conf);
return ERR_PTR(-EIO);
}
--
2.10.1

2016-10-06 09:29:25

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

On Thu, Oct 6, 2016 at 11:22 AM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Tue, 4 Oct 2016 21:46:18 +0200
>
> Replace the specification of a data structure by a pointer dereference
> as the parameter for the operator "sizeof" to make the corresponding size
> determination a bit safer.

Isn't this pure matter of taste?
Some developers prefer sizeof(*ptr) because it is easier to type, other
developers prefer sizeof(struct foo) because you can determine the type
at first sight and makes review more easy.

--
Thanks,
//richard

2016-10-06 09:29:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 29/54] md/raid5: Return directly after a failed kcalloc() in alloc_thread_groups()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 08:54:40 +0200

The kfree() function was called in up to two cases
by the alloc_thread_groups() function during error handling
even if the passed variable contained a null pointer.

* Return directly after a call of the kcalloc() function failed
at the beginning.

* Simplify a condition check for memory allocation failures.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b624ba6..d864871 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6265,10 +6265,12 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,
}
*group_cnt = num_possible_nodes();
workers = kcalloc(cnt * *group_cnt, sizeof(*workers), GFP_NOIO);
+ if (!workers)
+ return -ENOMEM;
+
*worker_groups = kcalloc(*group_cnt, sizeof(**worker_groups), GFP_NOIO);
- if (!*worker_groups || !workers) {
+ if (!*worker_groups) {
kfree(workers);
- kfree(*worker_groups);
return -ENOMEM;
}

--
2.10.1

2016-10-06 09:30:13

by SF Markus Elfring

[permalink] [raw]
Subject: MD-RAID: Fine-tuning for several function implementations

From: Markus Elfring <[email protected]>
Date: Wed, 6 Oct 2016 10:10:01 +0200

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (54):
raid0: Use kcalloc() in create_strip_zones()
raid0: Less function calls in create_strip_zones() after error detection
raid0: Move a variable assignment in create_strip_zones()
raid0: Replace printk() calls by the usage of higher level interfaces
raid0: Move another variable assignment in create_strip_zones()
raid0: Delete four unwanted spaces behind function names
raid0: Move two misplaced braces
raid0: Delete an unnecessary return statement in raid0_status()
raid0: Add some spaces for better code readability
raid1: Use kcalloc() in alloc_behind_pages()
raid1: Use kcalloc() in raid1_reshape()
raid1: Use kcalloc() in setup_conf()
raid1: Return directly after a failed kzalloc() in setup_conf()
raid1: Move assignments for the variable "err" in setup_conf()
raid1: Less function calls in setup_conf() after error detection
raid1: Delete an error message for a failed memory allocation
raid1: Move a brace for a designated initialiser
raid1: Adjust 12 checks for null pointers
raid1: Replace printk() calls by the usage of higher level interfaces
raid1: Add some spaces for better code readability
raid1: Delete three unwanted spaces behind asterisks
raid1: Delete three unwanted spaces before increment operators
raid1: Replace a seq_printf() call by seq_puts() in raid1_status()
raid1: Improve another size determination in setup_conf()
raid5: Use kcalloc() in three functions
raid5: Improve another size determination in setup_conf()
raid5: Return directly after a failed kzalloc() in setup_conf()
raid5: Rename a jump label in setup_conf()
raid5: Return directly after a failed kcalloc() in alloc_thread_groups()
raid5: Delete two error messages for a failed memory allocation
raid5: Adjust two function calls together with a variable assignment
raid5: Move a brace for three designated initialisers
raid5: Replace printk() calls by the usage of higher level interfaces
raid5: Delete indentation for two jump labels
raid5: Adjust 13 checks for null pointers
raid5: Delete four unwanted spaces behind function names
raid5: Replace a seq_printf() call by seq_puts() in raid5_status()
raid5: Move four asterisks
raid5: Add some spaces for better code readability
raid10: Use kcalloc() in two functions
raid10: Improve another size determination in setup_conf()
raid10: Delete an error message for a failed memory allocation
raid10: Return directly after detection of unsupported settings in setup_conf()
raid10: Return directly after a failed kzalloc() in setup_conf()
raid10: Move assignments for the variable "err" in setup_conf()
raid10: Less function calls in setup_conf() after error detection
raid10: Improve another size determination in raid10_start_reshape()
raid10: Move a brace for a designated initialiser
raid10: Replace printk() calls by the usage of higher level interfaces
raid10: Delete indentation for one jump label
raid10: Adjust 22 checks for null pointers
raid10: Replace a seq_printf() call by seq_puts() in raid10_status()
raid10: Delete two unwanted spaces behind asterisks
raid10: Add some spaces for better code readability

drivers/md/raid0.c | 170 ++++++++---------
drivers/md/raid1.c | 285 ++++++++++++++--------------
drivers/md/raid10.c | 366 ++++++++++++++++++------------------
drivers/md/raid5.c | 523 ++++++++++++++++++++++++----------------------------
4 files changed, 649 insertions(+), 695 deletions(-)

--
2.10.1

2016-10-06 09:31:10

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 30/54] md/raid5: Delete two error messages for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 09:43:40 +0200

Omit extra messages for a memory allocation failure in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d864871..ef180c0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6613,12 +6613,9 @@ static struct r5conf *setup_conf(struct mddev *mddev)
memory = conf->min_nr_stripes * (sizeof(struct stripe_head) +
max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS);
- if (grow_stripes(conf, conf->min_nr_stripes)) {
- printk(KERN_ERR
- "md/raid:%s: couldn't allocate %dkB for buffers\n",
- mdname(mddev), memory);
+ if (grow_stripes(conf, conf->min_nr_stripes))
goto free_conf;
- } else
+ else
printk(KERN_INFO "md/raid:%s: allocated %dkB\n",
mdname(mddev), memory);
/*
@@ -6640,12 +6637,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)

sprintf(pers_name, "raid%d", mddev->new_level);
conf->thread = md_register_thread(raid5d, mddev, pers_name);
- if (!conf->thread) {
- printk(KERN_ERR
- "md/raid:%s: couldn't allocate thread.\n",
- mdname(mddev));
+ if (!conf->thread)
goto free_conf;
- }

return conf;
free_conf:
--
2.10.1

2016-10-06 09:32:35

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 31/54] md/raid5: Adjust two function calls together with a variable assignment

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 10:00:07 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index ef180c0..a37f1f9 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -501,11 +501,10 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
int num = sh->raid_conf->pool_size;

for (i = 0; i < num; i++) {
- struct page *page;
+ struct page *page = alloc_page(gfp);

- if (!(page = alloc_page(gfp))) {
+ if (!page)
return 1;
- }
sh->dev[i].page = page;
sh->dev[i].orig_page = page;
}
@@ -6525,8 +6524,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
goto free_conf;

conf->mddev = mddev;
-
- if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
+ conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!conf->stripe_hashtbl)
goto free_conf;

/* We init hash_locks[0] separately to that it can be used
--
2.10.1

2016-10-06 09:33:06

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 32/54] md/raid5: Move a brace for three designated initialisers

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 10:20:05 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: that open brace { should be on the previous line

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index a37f1f9..f2473fa0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7868,8 +7868,7 @@ static void *raid6_takeover(struct mddev *mddev)
return setup_conf(mddev);
}

-static struct md_personality raid6_personality =
-{
+static struct md_personality raid6_personality = {
.name = "raid6",
.level = 6,
.owner = THIS_MODULE,
@@ -7891,8 +7890,7 @@ static struct md_personality raid6_personality =
.takeover = raid6_takeover,
.congested = raid5_congested,
};
-static struct md_personality raid5_personality =
-{
+static struct md_personality raid5_personality = {
.name = "raid5",
.level = 5,
.owner = THIS_MODULE,
@@ -7914,9 +7912,7 @@ static struct md_personality raid5_personality =
.takeover = raid5_takeover,
.congested = raid5_congested,
};
-
-static struct md_personality raid4_personality =
-{
+static struct md_personality raid4_personality = {
.name = "raid4",
.level = 4,
.owner = THIS_MODULE,
--
2.10.1

2016-10-06 09:33:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 33/54] md/raid5: Replace printk() calls by the usage of higher level interfaces

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 13:40:03 +0200

1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt"
so that their information can be used for consistent message output.

2. Prefer usage of some higher level macros over calling "printk" directly
in this software module.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 215 ++++++++++++++++++++++++-----------------------------
1 file changed, 96 insertions(+), 119 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f2473fa0..b0a14a6 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -43,6 +43,8 @@
* miss any bits.
*/

+#define MY_LOG_PREFIX KBUILD_MODNAME ": "
+#define pr_fmt(fmt) MY_LOG_PREFIX fmt
#include <linux/blkdev.h>
#include <linux/kthread.h>
#include <linux/raid/pq.h>
@@ -540,7 +542,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)

if (dev->toread || dev->read || dev->towrite || dev->written ||
test_bit(R5_LOCKED, &dev->flags)) {
- printk(KERN_ERR "sector=%llx i=%d %p %p %p %p %d\n",
+ pr_err("sector=%llx i=%d %p %p %p %p %d\n",
(unsigned long long)sh->sector, i, dev->toread,
dev->read, dev->towrite, dev->written,
test_bit(R5_LOCKED, &dev->flags));
@@ -2346,13 +2348,12 @@ static void raid5_end_read_request(struct bio * bi)
* replacement device. We just fail those on
* any error
*/
- printk_ratelimited(
- KERN_INFO
- "md/raid:%s: read error corrected"
- " (%lu sectors at %llu on %s)\n",
- mdname(conf->mddev), STRIPE_SECTORS,
- (unsigned long long)s,
- bdevname(rdev->bdev, b));
+ pr_info_ratelimited("%s: read error corrected ("
+ "%lu sectors at %llu on %s)\n",
+ mdname(conf->mddev),
+ STRIPE_SECTORS,
+ (unsigned long long)s,
+ bdevname(rdev->bdev, b));
atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
clear_bit(R5_ReadError, &sh->dev[i].flags);
clear_bit(R5_ReWrite, &sh->dev[i].flags);
@@ -2369,37 +2370,27 @@ static void raid5_end_read_request(struct bio * bi)
clear_bit(R5_UPTODATE, &sh->dev[i].flags);
atomic_inc(&rdev->read_errors);
if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
- printk_ratelimited(
- KERN_WARNING
- "md/raid:%s: read error on replacement device "
- "(sector %llu on %s).\n",
- mdname(conf->mddev),
- (unsigned long long)s,
- bdn);
+ pr_warn_ratelimited("%s: read error on replacement device (sector %llu on %s).\n",
+ mdname(conf->mddev),
+ (unsigned long long)s,
+ bdn);
else if (conf->mddev->degraded >= conf->max_degraded) {
set_bad = 1;
- printk_ratelimited(
- KERN_WARNING
- "md/raid:%s: read error not correctable "
- "(sector %llu on %s).\n",
- mdname(conf->mddev),
- (unsigned long long)s,
- bdn);
+ pr_warn_ratelimited("%s: read error not correctable (sector %llu on %s).\n",
+ mdname(conf->mddev),
+ (unsigned long long)s,
+ bdn);
} else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) {
/* Oh, no!!! */
set_bad = 1;
- printk_ratelimited(
- KERN_WARNING
- "md/raid:%s: read error NOT corrected!! "
- "(sector %llu on %s).\n",
- mdname(conf->mddev),
- (unsigned long long)s,
- bdn);
+ pr_warn_ratelimited("%s: read error NOT corrected! (sector %llu on %s).\n",
+ mdname(conf->mddev),
+ (unsigned long long)s,
+ bdn);
} else if (atomic_read(&rdev->read_errors)
> conf->max_nr_stripes)
- printk(KERN_WARNING
- "md/raid:%s: Too many read errors, failing device %s.\n",
- mdname(conf->mddev), bdn);
+ pr_warn("%s: Too many read errors, failing device %s.\n",
+ mdname(conf->mddev), bdn);
else
retry = 1;
if (set_bad && test_bit(In_sync, &rdev->flags)
@@ -2532,13 +2523,12 @@ static void raid5_error(struct mddev *mddev, struct md_rdev *rdev)
set_bit(Faulty, &rdev->flags);
set_mask_bits(&mddev->flags, 0,
BIT(MD_CHANGE_DEVS) | BIT(MD_CHANGE_PENDING));
- printk(KERN_ALERT
- "md/raid:%s: Disk failure on %s, disabling device.\n"
- "md/raid:%s: Operation continuing on %d devices.\n",
- mdname(mddev),
- bdevname(rdev->bdev, b),
- mdname(mddev),
- conf->raid_disks - mddev->degraded);
+ pr_alert("%s: Disk failure on %s, disabling device.\n"
+ MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n",
+ mdname(mddev),
+ bdevname(rdev->bdev, b),
+ mdname(mddev),
+ conf->raid_disks - mddev->degraded);
}

/*
@@ -2860,7 +2850,7 @@ sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous)
previous, &dummy1, &sh2);
if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx
|| sh2.qd_idx != sh->qd_idx) {
- printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n",
+ pr_err("%s: compute_blocknr: map not correct\n",
mdname(conf->mddev));
return 0;
}
@@ -3781,7 +3771,7 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,
case check_state_compute_run:
break;
default:
- printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n",
+ pr_err("%s: unknown check_state: %d sector: %llu\n",
__func__, sh->check_state,
(unsigned long long) sh->sector);
BUG();
@@ -3945,7 +3935,7 @@ static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,
case check_state_compute_run:
break;
default:
- printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n",
+ pr_err("%s: unknown check_state: %d sector: %llu\n",
__func__, sh->check_state,
(unsigned long long) sh->sector);
BUG();
@@ -6456,7 +6446,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
if (mddev->new_level != 5
&& mddev->new_level != 4
&& mddev->new_level != 6) {
- printk(KERN_ERR "md/raid:%s: raid level not set to 4/5/6 (%d)\n",
+ pr_err("%s: raid level not set to 4/5/6 (%d)\n",
mdname(mddev), mddev->new_level);
return ERR_PTR(-EIO);
}
@@ -6464,12 +6454,12 @@ static struct r5conf *setup_conf(struct mddev *mddev)
&& !algorithm_valid_raid5(mddev->new_layout)) ||
(mddev->new_level == 6
&& !algorithm_valid_raid6(mddev->new_layout))) {
- printk(KERN_ERR "md/raid:%s: layout %d not supported\n",
+ pr_err("%s: layout %d not supported\n",
mdname(mddev), mddev->new_layout);
return ERR_PTR(-EIO);
}
if (mddev->new_level == 6 && mddev->raid_disks < 4) {
- printk(KERN_ERR "md/raid:%s: not enough configured devices (%d, minimum 4)\n",
+ pr_err("%s: not enough configured devices (%d, minimum 4)\n",
mdname(mddev), mddev->raid_disks);
return ERR_PTR(-EINVAL);
}
@@ -6477,7 +6467,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
if (!mddev->new_chunk_sectors ||
(mddev->new_chunk_sectors << 9) % PAGE_SIZE ||
!is_power_of_2(mddev->new_chunk_sectors)) {
- printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n",
+ pr_err("%s: invalid chunk size %d\n",
mdname(mddev), mddev->new_chunk_sectors << 9);
return ERR_PTR(-EINVAL);
}
@@ -6569,8 +6559,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)

if (test_bit(In_sync, &rdev->flags)) {
char b[BDEVNAME_SIZE];
- printk(KERN_INFO "md/raid:%s: device %s operational as raid"
- " disk %d\n",
+ pr_info("%s: device %s operational as raid disk %d\n",
mdname(mddev), bdevname(rdev->bdev, b), raid_disk);
} else if (rdev->saved_raid_disk != raid_disk)
/* Cannot rely on bitmap to complete recovery */
@@ -6605,8 +6594,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4);
conf->min_nr_stripes = max(NR_STRIPES, stripes);
if (conf->min_nr_stripes != NR_STRIPES)
- printk(KERN_INFO
- "md/raid:%s: force stripe size %d for reshape\n",
+ pr_info("%s: force stripe size %d for reshape\n",
mdname(mddev), conf->min_nr_stripes);
}
memory = conf->min_nr_stripes * (sizeof(struct stripe_head) +
@@ -6615,8 +6603,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
if (grow_stripes(conf, conf->min_nr_stripes))
goto free_conf;
else
- printk(KERN_INFO "md/raid:%s: allocated %dkB\n",
- mdname(mddev), memory);
+ pr_info("%s: allocated %dkB\n", mdname(mddev), memory);
/*
* Losing a stripe head costs more than the time to refill it,
* it reduces the queue depth and so can hurt throughput.
@@ -6628,9 +6615,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
conf->shrinker.batch = 128;
conf->shrinker.flags = 0;
if (register_shrinker(&conf->shrinker)) {
- printk(KERN_ERR
- "md/raid:%s: couldn't register shrinker.\n",
- mdname(mddev));
+ pr_err("%s: couldn't register shrinker.\n", mdname(mddev));
goto free_conf;
}

@@ -6684,9 +6669,8 @@ static int raid5_run(struct mddev *mddev)
int first = 1;

if (mddev->recovery_cp != MaxSector)
- printk(KERN_NOTICE "md/raid:%s: not clean"
- " -- starting background reconstruction\n",
- mdname(mddev));
+ pr_notice("%s: not clean - starting background reconstruction\n",
+ mdname(mddev));

rdev_for_each(rdev, mddev) {
long long diff;
@@ -6729,15 +6713,14 @@ static int raid5_run(struct mddev *mddev)
int new_data_disks;

if (journal_dev) {
- printk(KERN_ERR "md/raid:%s: don't support reshape with journal - aborting.\n",
- mdname(mddev));
+ pr_err("%s: don't support reshape with journal%s",
+ mdname(mddev), " - aborting.\n");
return -EINVAL;
}

if (mddev->new_level != mddev->level) {
- printk(KERN_ERR "md/raid:%s: unsupported reshape "
- "required - aborting.\n",
- mdname(mddev));
+ pr_err("%s: unsupported reshape required%s",
+ mdname(mddev), " - aborting.\n");
return -EINVAL;
}
old_disks = mddev->raid_disks - mddev->delta_disks;
@@ -6752,8 +6735,8 @@ static int raid5_run(struct mddev *mddev)
chunk_sectors = max(mddev->chunk_sectors, mddev->new_chunk_sectors);
new_data_disks = mddev->raid_disks - max_degraded;
if (sector_div(here_new, chunk_sectors * new_data_disks)) {
- printk(KERN_ERR "md/raid:%s: reshape_position not "
- "on a stripe boundary\n", mdname(mddev));
+ pr_err("%s: reshape_position not on a stripe boundary\n",
+ mdname(mddev));
return -EINVAL;
}
reshape_offset = here_new * chunk_sectors;
@@ -6774,10 +6757,8 @@ static int raid5_run(struct mddev *mddev)
abs(min_offset_diff) >= mddev->new_chunk_sectors)
/* not really in-place - so OK */;
else if (mddev->ro == 0) {
- printk(KERN_ERR "md/raid:%s: in-place reshape "
- "must be started in read-only mode "
- "- aborting\n",
- mdname(mddev));
+ pr_err("%s: in-place reshape must be started in read-only mode%s",
+ mdname(mddev), " - aborting.\n");
return -EINVAL;
}
} else if (mddev->reshape_backwards
@@ -6786,13 +6767,11 @@ static int raid5_run(struct mddev *mddev)
: (here_new * chunk_sectors >=
here_old * chunk_sectors + (-min_offset_diff))) {
/* Reading from the same stripe as writing to - bad */
- printk(KERN_ERR "md/raid:%s: reshape_position too early for "
- "auto-recovery - aborting.\n",
- mdname(mddev));
+ pr_err("%s: reshape_position too early for auto-recovery%s",
+ mdname(mddev), " - aborting.\n");
return -EINVAL;
}
- printk(KERN_INFO "md/raid:%s: reshape will continue\n",
- mdname(mddev));
+ pr_info("%s: reshape will continue\n", mdname(mddev));
/* OK, we should be able to continue; */
} else {
BUG_ON(mddev->level != mddev->new_level);
@@ -6811,7 +6790,7 @@ static int raid5_run(struct mddev *mddev)

if (test_bit(MD_HAS_JOURNAL, &mddev->flags)) {
if (!journal_dev) {
- pr_err("md/raid:%s: journal disk is missing, force array readonly\n",
+ pr_err("%s: journal disk is missing, force array readonly\n",
mdname(mddev));
mddev->ro = 1;
set_disk_ro(mddev->gendisk, 1);
@@ -6839,8 +6818,7 @@ static int raid5_run(struct mddev *mddev)
if (conf->disks[i].replacement &&
conf->reshape_progress != MaxSector) {
/* replacements and reshape simply do not mix. */
- printk(KERN_ERR "md: cannot handle concurrent "
- "replacement and reshape.\n");
+ pr_err("cannot handle concurrent replacement and reshape.\n");
goto abort;
}
if (test_bit(In_sync, &rdev->flags)) {
@@ -6882,9 +6860,8 @@ static int raid5_run(struct mddev *mddev)
mddev->degraded = calc_degraded(conf);

if (has_failed(conf)) {
- printk(KERN_ERR "md/raid:%s: not enough operational devices"
- " (%d/%d failed)\n",
- mdname(mddev), mddev->degraded, conf->raid_disks);
+ pr_err("%s: not enough operational devices (%d/%d failed)\n",
+ mdname(mddev), mddev->degraded, conf->raid_disks);
goto abort;
}

@@ -6894,30 +6871,30 @@ static int raid5_run(struct mddev *mddev)

if (mddev->degraded > dirty_parity_disks &&
mddev->recovery_cp != MaxSector) {
- if (mddev->ok_start_degraded)
- printk(KERN_WARNING
- "md/raid:%s: starting dirty degraded array"
- " - data corruption possible.\n",
- mdname(mddev));
- else {
- printk(KERN_ERR
- "md/raid:%s: cannot start dirty degraded array.\n",
+ if (mddev->ok_start_degraded) {
+ pr_warn("%s: starting dirty degraded array - data corruption possible.\n",
+ mdname(mddev));
+ } else {
+ pr_err("%s: cannot start dirty degraded array.\n",
mdname(mddev));
goto abort;
}
}

if (mddev->degraded == 0)
- printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d"
- " devices, algorithm %d\n", mdname(mddev), conf->level,
- mddev->raid_disks-mddev->degraded, mddev->raid_disks,
- mddev->new_layout);
+ pr_info("%s: raid level %d active with %d out of %d devices, algorithm %d\n",
+ mdname(mddev),
+ conf->level,
+ mddev->raid_disks-mddev->degraded,
+ mddev->raid_disks,
+ mddev->new_layout);
else
- printk(KERN_ALERT "md/raid:%s: raid level %d active with %d"
- " out of %d devices, algorithm %d\n",
- mdname(mddev), conf->level,
- mddev->raid_disks - mddev->degraded,
- mddev->raid_disks, mddev->new_layout);
+ pr_alert("%s: raid level %d active with %d out of %d devices, algorithm %d\n",
+ mdname(mddev),
+ conf->level,
+ mddev->raid_disks - mddev->degraded,
+ mddev->raid_disks,
+ mddev->new_layout);

print_raid5_conf(conf);

@@ -6937,9 +6914,8 @@ static int raid5_run(struct mddev *mddev)
mddev->to_remove = NULL;
else if (mddev->kobj.sd &&
sysfs_create_group(&mddev->kobj, &raid5_attrs_group))
- printk(KERN_WARNING
- "raid5: failed to create sysfs attributes for %s\n",
- mdname(mddev));
+ pr_warn("failed to create sysfs attributes for %s\n",
+ mdname(mddev));
md_set_array_sectors(mddev, raid5_size(mddev, 0, 0));

if (mddev->queue) {
@@ -7027,8 +7003,8 @@ static int raid5_run(struct mddev *mddev)
if (journal_dev) {
char b[BDEVNAME_SIZE];

- printk(KERN_INFO"md/raid:%s: using device %s as journal\n",
- mdname(mddev), bdevname(journal_dev->bdev, b));
+ pr_info("%s: using device %s as journal\n",
+ mdname(mddev), bdevname(journal_dev->bdev, b));
r5l_init_log(conf, journal_dev);
}

@@ -7038,7 +7014,7 @@ static int raid5_run(struct mddev *mddev)
print_raid5_conf(conf);
free_conf(conf);
mddev->private = NULL;
- printk(KERN_ALERT "md/raid:%s: failed to run raid set.\n", mdname(mddev));
+ pr_alert("%s: failed to run raid set.\n", mdname(mddev));
return -EIO;
}

@@ -7072,22 +7048,23 @@ static void print_raid5_conf (struct r5conf *conf)
int i;
struct disk_info *tmp;

- printk(KERN_DEBUG "RAID conf printout:\n");
+ pr_debug("conf printout:\n");
if (!conf) {
- printk("(conf==NULL)\n");
+ pr_debug("(conf==NULL)\n");
return;
}
- printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level,
- conf->raid_disks,
- conf->raid_disks - conf->mddev->degraded);
+ pr_debug("--- level:%d rd:%d wd:%d\n",
+ conf->level,
+ conf->raid_disks,
+ conf->raid_disks - conf->mddev->degraded);

for (i = 0; i < conf->raid_disks; i++) {
char b[BDEVNAME_SIZE];
tmp = conf->disks + i;
if (tmp->rdev)
- printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n",
- i, !test_bit(Faulty, &tmp->rdev->flags),
- bdevname(tmp->rdev->bdev, b));
+ pr_debug("disk %d, o:%d, dev:%s\n",
+ i, !test_bit(Faulty, &tmp->rdev->flags),
+ bdevname(tmp->rdev->bdev, b));
}
}

@@ -7233,8 +7210,8 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
* write requests running. We should be safe
*/
r5l_init_log(conf, rdev);
- printk(KERN_INFO"md/raid:%s: using device %s as journal\n",
- mdname(mddev), bdevname(rdev->bdev, b));
+ pr_info("%s: using device %s as journal\n",
+ mdname(mddev), bdevname(rdev->bdev, b));
return 0;
}
if (mddev->recovery_disabled == conf->recovery_disabled)
@@ -7338,9 +7315,9 @@ static int check_stripe_cache(struct mddev *mddev)
> conf->min_nr_stripes ||
((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4
> conf->min_nr_stripes) {
- printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n",
- mdname(mddev),
- ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9)
+ pr_warn("%s: reshape: not enough stripes. Needed %lu\n",
+ mdname(mddev),
+ ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9)
/ STRIPE_SIZE)*4);
return 0;
}
@@ -7422,8 +7399,8 @@ static int raid5_start_reshape(struct mddev *mddev)
*/
if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks)
< mddev->array_sectors) {
- printk(KERN_ERR "md/raid:%s: array size must be reduced "
- "before number of disks\n", mdname(mddev));
+ pr_err("%s: array size must be reduced before number of disks\n",
+ mdname(mddev));
return -EINVAL;
}

@@ -7641,7 +7618,7 @@ static void *raid45_takeover_raid0(struct mddev *mddev, int level)

/* for raid0 takeover only one zone is supported */
if (raid0_conf->nr_strip_zones > 1) {
- printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n",
+ pr_err("%s: cannot takeover raid0 with more than one zone.\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
--
2.10.1

2016-10-06 09:34:27

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 34/54] md/raid5: Delete indentation for two jump labels

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 13:45:18 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: labels should not be indented

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b0a14a6..4debd86 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5089,7 +5089,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
logical_sector += STRIPE_SECTORS) {
DEFINE_WAIT(w);
int d;
- again:
+again:
sh = raid5_get_active_stripe(conf, logical_sector, 0, 0, 0);
prepare_to_wait(&conf->wait_for_overlap, &w,
TASK_UNINTERRUPTIBLE);
@@ -5204,7 +5204,7 @@ static void raid5_make_request(struct mddev *mddev, struct bio * bi)
int seq;

do_prepare = false;
- retry:
+retry:
seq = read_seqcount_begin(&conf->gen_lock);
previous = 0;
if (do_prepare)
--
2.10.1

2016-10-06 09:36:05

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 35/54] md/raid5: Adjust 13 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:07:49 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 4debd86..f7a3369 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -679,7 +679,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
set_bit(R5_ALLOC_MORE,
&conf->cache_state);
}
- if (noblock && sh == NULL)
+ if (noblock && !sh)
break;
if (!sh) {
set_bit(R5_INACTIVE_BLOCKED,
@@ -719,7 +719,7 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
atomic_inc(&sh->count);
spin_unlock(&conf->device_lock);
}
- } while (sh == NULL);
+ } while (!sh);

spin_unlock_irq(conf->hash_locks + hash);
return sh;
@@ -2260,7 +2260,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
list_del_init(&nsh->lru);

for (i=conf->raid_disks; i < newsize; i++)
- if (nsh->dev[i].page == NULL) {
+ if (!nsh->dev[i].page) {
struct page *p = alloc_page(GFP_NOIO);
nsh->dev[i].page = p;
nsh->dev[i].orig_page = p;
@@ -2977,7 +2977,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,
goto overlap;
if (forwrite) {
bip = &sh->dev[dd_idx].towrite;
- if (*bip == NULL)
+ if (!*bip)
firstwrite = 1;
} else
bip = &sh->dev[dd_idx].toread;
@@ -3962,7 +3962,7 @@ static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh)
sector_t s = raid5_compute_sector(conf, bn, 0,
&dd_idx, NULL);
sh2 = raid5_get_active_stripe(conf, s, 0, 1, 1);
- if (sh2 == NULL)
+ if (!sh2)
/* so far only the early blocks of this stripe
* have been requested. When later blocks
* get requested, we will try again
@@ -4094,7 +4094,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
if (rdev) {
is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS,
&first_bad, &bad_sectors);
- if (s->blocked_rdev == NULL
+ if (!s->blocked_rdev
&& (test_bit(Blocked, &rdev->flags)
|| is_bad < 0)) {
if (is_bad < 0)
@@ -5044,8 +5044,7 @@ static void release_stripe_plug(struct mddev *mddev,
}

cb = container_of(blk_cb, struct raid5_plug_cb, cb);
-
- if (cb->list.next == NULL) {
+ if (!cb->list.next) {
int i;
INIT_LIST_HEAD(&cb->list);
for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
@@ -5653,7 +5652,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
bitmap_cond_end_sync(mddev->bitmap, sector_nr, false);

sh = raid5_get_active_stripe(conf, sector_nr, 0, 1, 0);
- if (sh == NULL) {
+ if (!sh) {
sh = raid5_get_active_stripe(conf, sector_nr, 0, 0, 0);
/* make sure we don't swamp the stripe cache if someone else
* is trying to get access
@@ -5668,7 +5667,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
for (i = 0; i < conf->raid_disks; i++) {
struct md_rdev *rdev = ACCESS_ONCE(conf->disks[i].rdev);

- if (rdev == NULL || test_bit(Faulty, &rdev->flags))
+ if (!rdev || test_bit(Faulty, &rdev->flags))
still_degraded = 1;
}
rcu_read_unlock();
@@ -6780,7 +6779,7 @@ static int raid5_run(struct mddev *mddev)
BUG_ON(mddev->delta_disks != 0);
}

- if (mddev->private == NULL)
+ if (!mddev->private)
conf = setup_conf(mddev);
else
conf = mddev->private;
@@ -7230,12 +7229,12 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
*/
if (rdev->saved_raid_disk >= 0 &&
rdev->saved_raid_disk >= first &&
- conf->disks[rdev->saved_raid_disk].rdev == NULL)
+ !conf->disks[rdev->saved_raid_disk].rdev)
first = rdev->saved_raid_disk;

for (disk = first; disk <= last; disk++) {
p = conf->disks + disk;
- if (p->rdev == NULL) {
+ if (!p->rdev) {
clear_bit(In_sync, &rdev->flags);
rdev->raid_disk = disk;
err = 0;
@@ -7248,7 +7247,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
for (disk = first; disk <= last; disk++) {
p = conf->disks + disk;
if (test_bit(WantReplacement, &p->rdev->flags) &&
- p->replacement == NULL) {
+ !p->replacement) {
clear_bit(In_sync, &rdev->flags);
set_bit(Replacement, &rdev->flags);
rdev->raid_disk = disk;
--
2.10.1

2016-10-06 09:36:30

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 36/54] md/raid5: Delete four unwanted spaces behind function names

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:37:17 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: space prohibited between function name and open parenthesis '('

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f7a3369..ebcd692 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -236,7 +236,7 @@ static void return_io(struct bio_list *return_bi)
}
}

-static void print_raid5_conf (struct r5conf *conf);
+static void print_raid5_conf(struct r5conf *conf);

static int stripe_operations_active(struct stripe_head *sh)
{
@@ -7032,17 +7032,22 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)

seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level,
conf->chunk_sectors / 2, mddev->layout);
- seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded);
+ seq_printf(seq,
+ " [%d/%d] [",
+ conf->raid_disks,
+ conf->raid_disks - mddev->degraded);
rcu_read_lock();
for (i = 0; i < conf->raid_disks; i++) {
struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev);
- seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
+ seq_printf(seq,
+ "%s",
+ rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
seq_printf (seq, "]");
}

-static void print_raid5_conf (struct r5conf *conf)
+static void print_raid5_conf(struct r5conf *conf)
{
int i;
struct disk_info *tmp;
--
2.10.1

2016-10-06 09:37:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 14:40:27 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index ebcd692..7a825c0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf (seq, "]");
+ seq_puts(seq, "]");
}

static void print_raid5_conf(struct r5conf *conf)
--
2.10.1

2016-10-06 09:38:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 38/54] md/raid5: Move four asterisks

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 15:00:23 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: "foo* bar" should be "foo *bar"

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 7a825c0..5bcc1ff 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2306,7 +2306,7 @@ static void shrink_stripes(struct r5conf *conf)
conf->slab_cache = NULL;
}

-static void raid5_end_read_request(struct bio * bi)
+static void raid5_end_read_request(struct bio *bi)
{
struct stripe_head *sh = bi->bi_private;
struct r5conf *conf = sh->raid_conf;
@@ -4760,7 +4760,7 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)
*/
static void raid5_align_endio(struct bio *bi)
{
- struct bio* raid_bi = bi->bi_private;
+ struct bio *raid_bi = bi->bi_private;
struct mddev *mddev;
struct r5conf *conf;
struct md_rdev *rdev;
@@ -4793,7 +4793,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)
{
struct r5conf *conf = mddev->private;
int dd_idx;
- struct bio* align_bi;
+ struct bio *align_bi;
struct md_rdev *rdev;
sector_t end_sector;

@@ -5149,7 +5149,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
}
}

-static void raid5_make_request(struct mddev *mddev, struct bio * bi)
+static void raid5_make_request(struct mddev *mddev, struct bio *bi)
{
struct r5conf *conf = mddev->private;
int dd_idx;
--
2.10.1

2016-10-06 09:40:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 39/54] md/raid5: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:00:32 +0200

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid5.c | 165 +++++++++++++++++++++++++++--------------------------
1 file changed, 83 insertions(+), 82 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 5bcc1ff..e29c198 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -292,7 +292,7 @@ static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh,
struct list_head *temp_inactive_list)
{
BUG_ON(!list_empty(&sh->lru));
- BUG_ON(atomic_read(&conf->active_stripes)==0);
+ BUG_ON(atomic_read(&conf->active_stripes) == 0);
if (test_bit(STRIPE_HANDLE, &sh->state)) {
if (test_bit(STRIPE_DELAYED, &sh->state) &&
!test_bit(STRIPE_PREREAD_ACTIVE, &sh->state))
@@ -2224,7 +2224,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
osh = get_free_stripe(conf, hash);
unlock_device_hash_lock(conf, hash);

- for(i=0; i<conf->pool_size; i++) {
+ for (i = 0; i < conf->pool_size; i++) {
nsh->dev[i].page = osh->dev[i].page;
nsh->dev[i].orig_page = osh->dev[i].page;
}
@@ -2246,7 +2246,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
*/
ndisks = kcalloc(newsize, sizeof(*ndisks), GFP_NOIO);
if (ndisks) {
- for (i=0; i<conf->raid_disks; i++)
+ for (i = 0; i < conf->raid_disks; i++)
ndisks[i] = conf->disks[i];
kfree(conf->disks);
conf->disks = ndisks;
@@ -2255,11 +2255,11 @@ static int resize_stripes(struct r5conf *conf, int newsize)

mutex_unlock(&conf->cache_size_mutex);
/* Step 4, return new stripes to service */
- while(!list_empty(&newstripes)) {
+ while (!list_empty(&newstripes)) {
nsh = list_entry(newstripes.next, struct stripe_head, lru);
list_del_init(&nsh->lru);

- for (i=conf->raid_disks; i < newsize; i++)
+ for (i = conf->raid_disks; i < newsize; i++)
if (!nsh->dev[i].page) {
struct page *p = alloc_page(GFP_NOIO);
nsh->dev[i].page = p;
@@ -2315,7 +2315,7 @@ static void raid5_end_read_request(struct bio *bi)
struct md_rdev *rdev = NULL;
sector_t s;

- for (i=0 ; i<disks; i++)
+ for (i = 0 ; i < disks; i++)
if (bi == &sh->dev[i].req)
break;

@@ -2571,7 +2571,7 @@ sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector,
* Select the parity disk based on the user selected algorithm.
*/
pd_idx = qd_idx = -1;
- switch(conf->level) {
+ switch (conf->level) {
case 4:
pd_idx = data_disks;
break;
@@ -2759,7 +2759,7 @@ sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous)

if (i == sh->pd_idx)
return 0;
- switch(conf->level) {
+ switch (conf->level) {
case 4: break;
case 5:
switch (algorithm) {
@@ -2957,7 +2957,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,
{
struct bio **bip;
struct r5conf *conf = sh->raid_conf;
- int firstwrite=0;
+ int firstwrite = 0;

pr_debug("adding bi b#%llu to stripe s#%llu\n",
(unsigned long long)bi->bi_iter.bi_sector,
@@ -3001,7 +3001,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,
if (forwrite) {
/* check if page is covered */
sector_t sector = sh->dev[dd_idx].sector;
- for (bi=sh->dev[dd_idx].towrite;
+ for (bi = sh->dev[dd_idx].towrite;
sector < sh->dev[dd_idx].sector + STRIPE_SECTORS &&
bi && bi->bi_iter.bi_sector <= sector;
bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) {
@@ -3639,7 +3639,8 @@ static void handle_stripe_dirtying(struct r5conf *conf,
}
if ((rcw < rmw || (rcw == rmw && conf->rmw_level != PARITY_PREFER_RMW)) && rcw > 0) {
/* want reconstruct write, but need to get some data */
- int qread =0;
+ int qread = 0;
+
rcw = 0;
for (i = disks; i--; ) {
struct r5dev *dev = &sh->dev[i];
@@ -4031,7 +4032,7 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)

/* Now to look around and see what can be done */
rcu_read_lock();
- for (i=disks; i--; ) {
+ for (i = disks; i--; ) {
struct md_rdev *rdev;
sector_t first_bad;
int bad_sectors;
@@ -4716,7 +4717,7 @@ static int in_chunk_boundary(struct mddev *mddev, struct bio *bio)
* add bio to the retry LIFO ( in O(1) ... we are in interrupt )
* later sampled by raid5d.
*/
-static void add_bio_to_retry(struct bio *bi,struct r5conf *conf)
+static void add_bio_to_retry(struct bio *bi, struct r5conf *conf)
{
unsigned long flags;

@@ -4739,7 +4740,7 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)
return bi;
}
bi = conf->retry_read_aligned_list;
- if(bi) {
+ if (bi) {
conf->retry_read_aligned_list = bi->bi_next;
bi->bi_next = NULL;
/*
@@ -4768,7 +4769,7 @@ static void raid5_align_endio(struct bio *bi)

bio_put(bi);

- rdev = (void*)raid_bi->bi_next;
+ rdev = (void *)raid_bi->bi_next;
raid_bi->bi_next = NULL;
mddev = rdev->mddev;
conf = mddev->private;
@@ -4838,7 +4839,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)

atomic_inc(&rdev->nr_pending);
rcu_read_unlock();
- raid_bio->bi_next = (void*)rdev;
+ raid_bio->bi_next = (void *)rdev;
align_bi->bi_bdev = rdev->bdev;
bio_clear_flag(align_bi, BIO_SEG_VALID);

@@ -5198,7 +5199,7 @@ static void raid5_make_request(struct mddev *mddev, struct bio *bi)
bi->bi_phys_segments = 1; /* over-loaded to count active stripes */

prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
- for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
+ for (; logical_sector < last_sector; logical_sector += STRIPE_SECTORS) {
int previous;
int seq;

@@ -5464,10 +5465,10 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
if ((mddev->reshape_backwards
? (safepos > writepos && readpos < writepos)
: (safepos < writepos && readpos > writepos)) ||
- time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) {
+ time_after(jiffies, conf->reshape_checkpoint + 10 * HZ)) {
/* Cannot proceed until we've updated the superblock... */
wait_event(conf->wait_for_overlap,
- atomic_read(&conf->reshape_stripes)==0
+ atomic_read(&conf->reshape_stripes) == 0
|| test_bit(MD_RECOVERY_INTR, &mddev->recovery));
if (atomic_read(&conf->reshape_stripes) != 0)
return 0;
@@ -5497,7 +5498,7 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
/* If any of this stripe is beyond the end of the old
* array, then we need to zero those blocks
*/
- for (j=sh->disks; j--;) {
+ for (j = sh->disks; j--;) {
sector_t s;
if (j == sh->pd_idx)
continue;
@@ -6406,7 +6407,7 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink,
unsigned long ret = SHRINK_STOP;

if (mutex_trylock(&conf->cache_size_mutex)) {
- ret= 0;
+ ret = 0;
while (ret < sc->nr_to_scan &&
conf->max_nr_stripes > conf->min_nr_stripes) {
if (drop_one_stripe(conf) == 0) {
@@ -7582,7 +7583,7 @@ static void raid5_quiesce(struct mddev *mddev, int state)
{
struct r5conf *conf = mddev->private;

- switch(state) {
+ switch (state) {
case 2: /* resume for a suspend */
wake_up(&conf->wait_for_overlap);
break;
@@ -7850,70 +7851,70 @@ static void *raid6_takeover(struct mddev *mddev)
}

static struct md_personality raid6_personality = {
- .name = "raid6",
- .level = 6,
- .owner = THIS_MODULE,
- .make_request = raid5_make_request,
- .run = raid5_run,
- .free = raid5_free,
- .status = raid5_status,
- .error_handler = raid5_error,
- .hot_add_disk = raid5_add_disk,
- .hot_remove_disk= raid5_remove_disk,
- .spare_active = raid5_spare_active,
- .sync_request = raid5_sync_request,
- .resize = raid5_resize,
- .size = raid5_size,
- .check_reshape = raid6_check_reshape,
- .start_reshape = raid5_start_reshape,
- .finish_reshape = raid5_finish_reshape,
- .quiesce = raid5_quiesce,
- .takeover = raid6_takeover,
- .congested = raid5_congested,
+ .name = "raid6",
+ .level = 6,
+ .owner = THIS_MODULE,
+ .make_request = raid5_make_request,
+ .run = raid5_run,
+ .free = raid5_free,
+ .status = raid5_status,
+ .error_handler = raid5_error,
+ .hot_add_disk = raid5_add_disk,
+ .hot_remove_disk = raid5_remove_disk,
+ .spare_active = raid5_spare_active,
+ .sync_request = raid5_sync_request,
+ .resize = raid5_resize,
+ .size = raid5_size,
+ .check_reshape = raid6_check_reshape,
+ .start_reshape = raid5_start_reshape,
+ .finish_reshape = raid5_finish_reshape,
+ .quiesce = raid5_quiesce,
+ .takeover = raid6_takeover,
+ .congested = raid5_congested,
};
static struct md_personality raid5_personality = {
- .name = "raid5",
- .level = 5,
- .owner = THIS_MODULE,
- .make_request = raid5_make_request,
- .run = raid5_run,
- .free = raid5_free,
- .status = raid5_status,
- .error_handler = raid5_error,
- .hot_add_disk = raid5_add_disk,
- .hot_remove_disk= raid5_remove_disk,
- .spare_active = raid5_spare_active,
- .sync_request = raid5_sync_request,
- .resize = raid5_resize,
- .size = raid5_size,
- .check_reshape = raid5_check_reshape,
- .start_reshape = raid5_start_reshape,
- .finish_reshape = raid5_finish_reshape,
- .quiesce = raid5_quiesce,
- .takeover = raid5_takeover,
- .congested = raid5_congested,
+ .name = "raid5",
+ .level = 5,
+ .owner = THIS_MODULE,
+ .make_request = raid5_make_request,
+ .run = raid5_run,
+ .free = raid5_free,
+ .status = raid5_status,
+ .error_handler = raid5_error,
+ .hot_add_disk = raid5_add_disk,
+ .hot_remove_disk = raid5_remove_disk,
+ .spare_active = raid5_spare_active,
+ .sync_request = raid5_sync_request,
+ .resize = raid5_resize,
+ .size = raid5_size,
+ .check_reshape = raid5_check_reshape,
+ .start_reshape = raid5_start_reshape,
+ .finish_reshape = raid5_finish_reshape,
+ .quiesce = raid5_quiesce,
+ .takeover = raid5_takeover,
+ .congested = raid5_congested,
};
static struct md_personality raid4_personality = {
- .name = "raid4",
- .level = 4,
- .owner = THIS_MODULE,
- .make_request = raid5_make_request,
- .run = raid5_run,
- .free = raid5_free,
- .status = raid5_status,
- .error_handler = raid5_error,
- .hot_add_disk = raid5_add_disk,
- .hot_remove_disk= raid5_remove_disk,
- .spare_active = raid5_spare_active,
- .sync_request = raid5_sync_request,
- .resize = raid5_resize,
- .size = raid5_size,
- .check_reshape = raid5_check_reshape,
- .start_reshape = raid5_start_reshape,
- .finish_reshape = raid5_finish_reshape,
- .quiesce = raid5_quiesce,
- .takeover = raid4_takeover,
- .congested = raid5_congested,
+ .name = "raid4",
+ .level = 4,
+ .owner = THIS_MODULE,
+ .make_request = raid5_make_request,
+ .run = raid5_run,
+ .free = raid5_free,
+ .status = raid5_status,
+ .error_handler = raid5_error,
+ .hot_add_disk = raid5_add_disk,
+ .hot_remove_disk = raid5_remove_disk,
+ .spare_active = raid5_spare_active,
+ .sync_request = raid5_sync_request,
+ .resize = raid5_resize,
+ .size = raid5_size,
+ .check_reshape = raid5_check_reshape,
+ .start_reshape = raid5_start_reshape,
+ .finish_reshape = raid5_finish_reshape,
+ .quiesce = raid5_quiesce,
+ .takeover = raid4_takeover,
+ .congested = raid5_congested,
};

static int __init raid5_init(void)
--
2.10.1

2016-10-06 09:40:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 40/54] md/raid10: Use kcalloc() in two functions

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:45:05 +0200

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index be1a9fc..17352a9 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3504,8 +3504,8 @@ static struct r10conf *setup_conf(struct mddev *mddev)
goto out;

/* FIXME calc properly */
- conf->mirrors = kzalloc(sizeof(struct raid10_info)*(mddev->raid_disks +
- max(0,-mddev->delta_disks)),
+ conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
+ sizeof(*conf->mirrors),
GFP_KERNEL);
if (!conf->mirrors)
goto out;
@@ -3936,11 +3936,10 @@ static int raid10_check_reshape(struct mddev *mddev)
conf->mirrors_new = NULL;
if (mddev->delta_disks > 0) {
/* allocate new 'mirrors' list */
- conf->mirrors_new = kzalloc(
- sizeof(struct raid10_info)
- *(mddev->raid_disks +
- mddev->delta_disks),
- GFP_KERNEL);
+ conf->mirrors_new = kcalloc(mddev->raid_disks
+ + mddev->delta_disks,
+ sizeof(*conf->mirrors_new),
+ GFP_KERNEL);
if (!conf->mirrors_new)
return -ENOMEM;
}
--
2.10.1

2016-10-06 09:41:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 41/54] md/raid10: Improve another size determination in setup_conf()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:51:52 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 17352a9..04e8f78 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3499,7 +3499,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
}

err = -ENOMEM;
- conf = kzalloc(sizeof(struct r10conf), GFP_KERNEL);
+ conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
goto out;

--
2.10.1

2016-10-06 09:43:05

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 42/54] md/raid10: Delete an error message for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 16:57:19 +0200

Omit an extra message for a memory allocation failure
(and another corresponding condition check) in this function.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 04e8f78..1f712f7 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3554,9 +3554,6 @@ static struct r10conf *setup_conf(struct mddev *mddev)
return conf;

out:
- if (err == -ENOMEM)
- printk(KERN_ERR "md/raid10:%s: couldn't allocate memory.\n",
- mdname(mddev));
if (conf) {
mempool_destroy(conf->r10bio_pool);
kfree(conf->mirrors);
--
2.10.1

2016-10-06 09:44:07

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 43/54] md/raid10: Return directly after detection of unsupported settings in setup_conf()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 17:32:49 +0200

* Return directly after unsupported system settings were detected
at the beginning.

* Delete the explicit initialisation for the local variables "conf"
and "err" which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1f712f7..8326e68 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3478,8 +3478,8 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)

static struct r10conf *setup_conf(struct mddev *mddev)
{
- struct r10conf *conf = NULL;
- int err = -EINVAL;
+ struct r10conf *conf;
+ int err;
struct geom geo;
int copies;

@@ -3489,13 +3489,13 @@ static struct r10conf *setup_conf(struct mddev *mddev)
printk(KERN_ERR "md/raid10:%s: chunk size must be "
"at least PAGE_SIZE(%ld) and be a power of 2.\n",
mdname(mddev), PAGE_SIZE);
- goto out;
+ return ERR_PTR(-EINVAL);
}

if (copies < 2 || copies > mddev->raid_disks) {
printk(KERN_ERR "md/raid10:%s: unsupported raid10 layout: 0x%8x\n",
mdname(mddev), mddev->new_layout);
- goto out;
+ return ERR_PTR(-EINVAL);
}

err = -ENOMEM;
--
2.10.1

2016-10-06 09:44:59

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 44/54] md/raid10: Return directly after a failed kzalloc() in setup_conf()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 17:46:02 +0200

* Return directly after a call of the function "kzalloc" failed
at the beginning.

* Delete a repeated check for the local variable "conf"
which became unnecessary with this refactoring.

* Reorder calls for the functions "kfree" and "safe_put_page"
at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 8326e68..abe75c2 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3501,7 +3501,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
err = -ENOMEM;
conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
- goto out;
+ return ERR_PTR(-ENOMEM);

/* FIXME calc properly */
conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
@@ -3554,12 +3554,10 @@ static struct r10conf *setup_conf(struct mddev *mddev)
return conf;

out:
- if (conf) {
- mempool_destroy(conf->r10bio_pool);
- kfree(conf->mirrors);
- safe_put_page(conf->tmppage);
- kfree(conf);
- }
+ mempool_destroy(conf->r10bio_pool);
+ safe_put_page(conf->tmppage);
+ kfree(conf->mirrors);
+ kfree(conf);
return ERR_PTR(err);
}

--
2.10.1

2016-10-06 09:46:20

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 45/54] md/raid10: Move assignments for the variable "err" in setup_conf()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:26:45 +0200

One local variable was set to an error code before a concrete
error situation was detected. Thus move the corresponding assignments
into if branches to indicate a memory allocation failure there.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index abe75c2..7e512d4 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3498,7 +3498,6 @@ static struct r10conf *setup_conf(struct mddev *mddev)
return ERR_PTR(-EINVAL);
}

- err = -ENOMEM;
conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
return ERR_PTR(-ENOMEM);
@@ -3507,19 +3506,25 @@ static struct r10conf *setup_conf(struct mddev *mddev)
conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
sizeof(*conf->mirrors),
GFP_KERNEL);
- if (!conf->mirrors)
+ if (!conf->mirrors) {
+ err = -ENOMEM;
goto out;
+ }

conf->tmppage = alloc_page(GFP_KERNEL);
- if (!conf->tmppage)
+ if (!conf->tmppage) {
+ err = -ENOMEM;
goto out;
+ }

conf->geo = geo;
conf->copies = copies;
conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc,
r10bio_pool_free, conf);
- if (!conf->r10bio_pool)
+ if (!conf->r10bio_pool) {
+ err = -ENOMEM;
goto out;
+ }

calc_sectors(conf, mddev->dev_sectors);
if (mddev->reshape_position == MaxSector) {
@@ -3547,8 +3552,10 @@ static struct r10conf *setup_conf(struct mddev *mddev)
atomic_set(&conf->nr_pending, 0);

conf->thread = md_register_thread(raid10d, mddev, "raid10");
- if (!conf->thread)
+ if (!conf->thread) {
+ err = -ENOMEM;
goto out;
+ }

conf->mddev = mddev;
return conf;
--
2.10.1

2016-10-06 09:47:10

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 46/54] md/raid10: Less function calls in setup_conf() after error detection

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:32:30 +0200

Resource release functions were called in up to three cases
by the setup_conf() function during error handling even if
the passed data structure members contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 7e512d4..9b8d11f 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3508,13 +3508,13 @@ static struct r10conf *setup_conf(struct mddev *mddev)
GFP_KERNEL);
if (!conf->mirrors) {
err = -ENOMEM;
- goto out;
+ goto free_conf;
}

conf->tmppage = alloc_page(GFP_KERNEL);
if (!conf->tmppage) {
err = -ENOMEM;
- goto out;
+ goto kfree_mirrors;
}

conf->geo = geo;
@@ -3523,7 +3523,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
r10bio_pool_free, conf);
if (!conf->r10bio_pool) {
err = -ENOMEM;
- goto out;
+ goto put_page;
}

calc_sectors(conf, mddev->dev_sectors);
@@ -3533,7 +3533,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
} else {
if (setup_geo(&conf->prev, mddev, geo_old) != conf->copies) {
err = -EINVAL;
- goto out;
+ goto destroy_pool;
}
conf->reshape_progress = mddev->reshape_position;
if (conf->prev.far_offset)
@@ -3554,16 +3554,18 @@ static struct r10conf *setup_conf(struct mddev *mddev)
conf->thread = md_register_thread(raid10d, mddev, "raid10");
if (!conf->thread) {
err = -ENOMEM;
- goto out;
+ goto destroy_pool;
}

conf->mddev = mddev;
return conf;
-
- out:
+destroy_pool:
mempool_destroy(conf->r10bio_pool);
+put_page:
safe_put_page(conf->tmppage);
+kfree_mirrors:
kfree(conf->mirrors);
+free_conf:
kfree(conf);
return ERR_PTR(err);
}
--
2.10.1

2016-10-06 09:47:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 47/54] md/raid10: Improve another size determination in raid10_start_reshape()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 18:48:17 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 9b8d11f..62cd159 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4065,7 +4065,7 @@ static int raid10_start_reshape(struct mddev *mddev)
spin_lock_irq(&conf->device_lock);
if (conf->mirrors_new) {
memcpy(conf->mirrors_new, conf->mirrors,
- sizeof(struct raid10_info)*conf->prev.raid_disks);
+ sizeof(*conf->mirrors_new) * conf->prev.raid_disks);
smp_mb();
kfree(conf->mirrors_old);
conf->mirrors_old = conf->mirrors;
--
2.10.1

2016-10-06 09:49:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 48/54] md/raid10: Move a brace for a designated initialiser

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 20:03:32 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: that open brace { should be on the previous line

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 62cd159..5119846 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4676,8 +4676,7 @@ static void raid10_finish_reshape(struct mddev *mddev)
mddev->reshape_backwards = 0;
}

-static struct md_personality raid10_personality =
-{
+static struct md_personality raid10_personality = {
.name = "raid10",
.level = 10,
.owner = THIS_MODULE,
--
2.10.1

2016-10-06 09:49:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:00:05 +0200

1. Add a definition for the macros "MY_LOG_PREFIX" and "pr_fmt"
so that their information can be used for consistent message output.

2. Prefer usage of some higher level macros over calling "printk" directly
in this software module.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 168 +++++++++++++++++++++++-----------------------------
1 file changed, 74 insertions(+), 94 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 5119846..0f2cb20 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -18,6 +18,8 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

+#define MY_LOG_PREFIX KBUILD_MODNAME ": "
+#define pr_fmt(fmt) MY_LOG_PREFIX fmt
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/blkdev.h>
@@ -404,8 +406,8 @@ static void raid10_end_read_request(struct bio *bio)
* oops, read error - keep the refcount on the rdev
*/
char b[BDEVNAME_SIZE];
- printk_ratelimited(KERN_ERR
- "md/raid10:%s: %s: rescheduling sector %llu\n",
+
+ pr_err_ratelimited("%s: %s: rescheduling sector %llu\n",
mdname(conf->mddev),
bdevname(rdev->bdev, b),
(unsigned long long)r10_bio->sector);
@@ -1586,11 +1588,10 @@ static void raid10_error(struct mddev *mddev, struct md_rdev *rdev)
set_mask_bits(&mddev->flags, 0,
BIT(MD_CHANGE_DEVS) | BIT(MD_CHANGE_PENDING));
spin_unlock_irqrestore(&conf->device_lock, flags);
- printk(KERN_ALERT
- "md/raid10:%s: Disk failure on %s, disabling device.\n"
- "md/raid10:%s: Operation continuing on %d devices.\n",
- mdname(mddev), bdevname(rdev->bdev, b),
- mdname(mddev), conf->geo.raid_disks - mddev->degraded);
+ pr_alert("%s: Disk failure on %s, disabling device.\n"
+ MY_LOG_PREFIX "%s: Operation continuing on %d devices.\n",
+ mdname(mddev), bdevname(rdev->bdev, b),
+ mdname(mddev), conf->geo.raid_disks - mddev->degraded);
}

static void print_conf(struct r10conf *conf)
@@ -1598,13 +1599,14 @@ static void print_conf(struct r10conf *conf)
int i;
struct md_rdev *rdev;

- printk(KERN_DEBUG "RAID10 conf printout:\n");
+ pr_debug("conf printout:\n");
if (!conf) {
- printk(KERN_DEBUG "(!conf)\n");
+ pr_debug("(!conf)\n");
return;
}
- printk(KERN_DEBUG " --- wd:%d rd:%d\n", conf->geo.raid_disks - conf->mddev->degraded,
- conf->geo.raid_disks);
+ pr_debug("--- wd:%d rd:%d\n",
+ conf->geo.raid_disks - conf->mddev->degraded,
+ conf->geo.raid_disks);

/* This is only called with ->reconfix_mutex held, so
* rcu protection of rdev is not needed */
@@ -1612,10 +1614,10 @@ static void print_conf(struct r10conf *conf)
char b[BDEVNAME_SIZE];
rdev = conf->mirrors[i].rdev;
if (rdev)
- printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n",
- i, !test_bit(In_sync, &rdev->flags),
- !test_bit(Faulty, &rdev->flags),
- bdevname(rdev->bdev,b));
+ pr_debug("disk %d, wo:%d, o:%d, dev:%s\n",
+ i, !test_bit(In_sync, &rdev->flags),
+ !test_bit(Faulty, &rdev->flags),
+ bdevname(rdev->bdev, b));
}
}

@@ -2106,11 +2108,8 @@ static void fix_recovery_read_error(struct r10bio *r10_bio)
ok = rdev_set_badblocks(rdev2, addr, s, 0);
if (!ok) {
/* just abort the recovery */
- printk(KERN_NOTICE
- "md/raid10:%s: recovery aborted"
- " due to read error\n",
- mdname(mddev));
-
+ pr_notice("%s: recovery aborted due to read error\n",
+ mdname(mddev));
conf->mirrors[dw].recovery_disabled
= mddev->recovery_disabled;
set_bit(MD_RECOVERY_INTR,
@@ -2256,14 +2255,10 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
char b[BDEVNAME_SIZE];
bdevname(rdev->bdev, b);

- printk(KERN_NOTICE
- "md/raid10:%s: %s: Raid device exceeded "
- "read_error threshold [cur %d:max %d]\n",
- mdname(mddev), b,
- atomic_read(&rdev->read_errors), max_read_errors);
- printk(KERN_NOTICE
- "md/raid10:%s: %s: Failing raid device\n",
- mdname(mddev), b);
+ pr_notice("%s: %s: Raid device exceeded read_error threshold [cur %d:max %d]\n",
+ mdname(mddev), b,
+ atomic_read(&rdev->read_errors), max_read_errors);
+ pr_notice("%s: %s: Failing raid device\n", mdname(mddev), b);
md_error(mddev, rdev);
r10_bio->devs[r10_bio->read_slot].bio = IO_BLOCKED;
return;
@@ -2353,20 +2348,17 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
s, conf->tmppage, WRITE)
== 0) {
/* Well, this device is dead */
- printk(KERN_NOTICE
- "md/raid10:%s: read correction "
- "write failed"
- " (%d sectors at %llu on %s)\n",
- mdname(mddev), s,
- (unsigned long long)(
- sect +
- choose_data_offset(r10_bio,
- rdev)),
- bdevname(rdev->bdev, b));
- printk(KERN_NOTICE "md/raid10:%s: %s: failing "
- "drive\n",
- mdname(mddev),
- bdevname(rdev->bdev, b));
+ pr_notice("%s: read correction write failed ("
+ "%d sectors at %llu on %s)\n",
+ mdname(mddev),
+ s,
+ (unsigned long long)
+ (sect
+ + choose_data_offset(r10_bio, rdev)),
+ bdevname(rdev->bdev, b));
+ pr_notice("%s: %s: failing drive\n",
+ mdname(mddev),
+ bdevname(rdev->bdev, b));
}
rdev_dec_pending(rdev, mddev);
rcu_read_lock();
@@ -2394,29 +2386,27 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
READ)) {
case 0:
/* Well, this device is dead */
- printk(KERN_NOTICE
- "md/raid10:%s: unable to read back "
- "corrected sectors"
- " (%d sectors at %llu on %s)\n",
- mdname(mddev), s,
- (unsigned long long)(
- sect +
- choose_data_offset(r10_bio, rdev)),
- bdevname(rdev->bdev, b));
- printk(KERN_NOTICE "md/raid10:%s: %s: failing "
- "drive\n",
- mdname(mddev),
- bdevname(rdev->bdev, b));
+ pr_notice("%s: unable to read back corrected sectors ("
+ "%d sectors at %llu on %s)\n",
+ mdname(mddev),
+ s,
+ (unsigned long long)
+ (sect
+ + choose_data_offset(r10_bio, rdev)),
+ bdevname(rdev->bdev, b));
+ pr_notice("%s: %s: failing drive\n",
+ mdname(mddev),
+ bdevname(rdev->bdev, b));
break;
case 1:
- printk(KERN_INFO
- "md/raid10:%s: read error corrected"
- " (%d sectors at %llu on %s)\n",
- mdname(mddev), s,
- (unsigned long long)(
- sect +
- choose_data_offset(r10_bio, rdev)),
- bdevname(rdev->bdev, b));
+ pr_info("%s: read error corrected ("
+ "%d sectors at %llu on %s)\n",
+ mdname(mddev),
+ s,
+ (unsigned long long)
+ (sect
+ + choose_data_offset(r10_bio, rdev)),
+ bdevname(rdev->bdev, b));
atomic_add(s, &rdev->corrected_errors);
}

@@ -2526,23 +2516,19 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)
read_more:
rdev = read_balance(conf, r10_bio, &max_sectors);
if (rdev == NULL) {
- printk(KERN_ALERT "md/raid10:%s: %s: unrecoverable I/O"
- " read error for block %llu\n",
- mdname(mddev), b,
- (unsigned long long)r10_bio->sector);
+ pr_alert("%s: %s: unrecoverable I/O read error for block %llu\n",
+ mdname(mddev), b,
+ (unsigned long long)r10_bio->sector);
raid_end_bio_io(r10_bio);
return;
}

do_sync = (r10_bio->master_bio->bi_opf & REQ_SYNC);
slot = r10_bio->read_slot;
- printk_ratelimited(
- KERN_ERR
- "md/raid10:%s: %s: redirecting "
- "sector %llu to another mirror\n",
- mdname(mddev),
- bdevname(rdev->bdev, b),
- (unsigned long long)r10_bio->sector);
+ pr_err_ratelimited("%s: %s: redirecting sector %llu to another mirror\n",
+ mdname(mddev),
+ bdevname(rdev->bdev, b),
+ (unsigned long long)r10_bio->sector);
bio = bio_clone_mddev(r10_bio->master_bio,
GFP_NOIO, mddev);
bio_trim(bio, r10_bio->sector - bio->bi_iter.bi_sector, max_sectors);
@@ -3157,9 +3143,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
if (!any_working) {
if (!test_and_set_bit(MD_RECOVERY_INTR,
&mddev->recovery))
- printk(KERN_INFO "md/raid10:%s: insufficient "
- "working devices for recovery.\n",
- mdname(mddev));
+ pr_info("%s: insufficient working devices for recovery.\n",
+ mdname(mddev));
mirror->recovery_disabled
= mddev->recovery_disabled;
}
@@ -3486,14 +3471,13 @@ static struct r10conf *setup_conf(struct mddev *mddev)
copies = setup_geo(&geo, mddev, geo_new);

if (copies == -2) {
- printk(KERN_ERR "md/raid10:%s: chunk size must be "
- "at least PAGE_SIZE(%ld) and be a power of 2.\n",
+ pr_err("%s: chunk size must be at least PAGE_SIZE(%ld) and be a power of 2.\n",
mdname(mddev), PAGE_SIZE);
return ERR_PTR(-EINVAL);
}

if (copies < 2 || copies > mddev->raid_disks) {
- printk(KERN_ERR "md/raid10:%s: unsupported raid10 layout: 0x%8x\n",
+ pr_err("%s: unsupported raid10 layout: 0x%8x\n",
mdname(mddev), mddev->new_layout);
return ERR_PTR(-EINVAL);
}
@@ -3657,8 +3641,7 @@ static int raid10_run(struct mddev *mddev)
}
/* need to check that every block has at least one working mirror */
if (!enough(conf, -1)) {
- printk(KERN_ERR "md/raid10:%s: not enough operational mirrors.\n",
- mdname(mddev));
+ pr_err("%s: not enough operational mirrors.\n", mdname(mddev));
goto out_free_conf;
}

@@ -3699,12 +3682,11 @@ static int raid10_run(struct mddev *mddev)
}

if (mddev->recovery_cp != MaxSector)
- printk(KERN_NOTICE "md/raid10:%s: not clean"
- " -- starting background reconstruction\n",
- mdname(mddev));
- printk(KERN_INFO
- "md/raid10:%s: active with %d out of %d devices\n",
- mdname(mddev), conf->geo.raid_disks - mddev->degraded,
+ pr_notice("%s: not clean - starting background reconstruction\n",
+ mdname(mddev));
+ pr_info("%s: active with %d out of %d devices\n",
+ mdname(mddev),
+ conf->geo.raid_disks - mddev->degraded,
conf->geo.raid_disks);
/*
* Ok, everything is just fine now
@@ -3740,7 +3722,7 @@ static int raid10_run(struct mddev *mddev)

if (max(before_length, after_length) > min_offset_diff) {
/* This cannot work */
- printk("md/raid10: offset difference not enough to continue reshape\n");
+ pr_notice("offset difference not enough to continue reshape\n");
goto out_free_conf;
}
conf->offset_diff = min_offset_diff;
@@ -3847,8 +3829,7 @@ static void *raid10_takeover_raid0(struct mddev *mddev, sector_t size, int devs)
struct r10conf *conf;

if (mddev->degraded > 0) {
- printk(KERN_ERR "md/raid10:%s: Error: degraded raid0!\n",
- mdname(mddev));
+ pr_err("%s: Error: degraded raid0!\n", mdname(mddev));
return ERR_PTR(-EINVAL);
}
sector_div(size, devs);
@@ -3888,8 +3869,7 @@ static void *raid10_takeover(struct mddev *mddev)
/* for raid0 takeover only one zone is supported */
raid0_conf = mddev->private;
if (raid0_conf->nr_strip_zones > 1) {
- printk(KERN_ERR "md/raid10:%s: cannot takeover raid 0"
- " with more than one zone.\n",
+ pr_err("%s: cannot takeover raid 0 with more than one zone.\n",
mdname(mddev));
return ERR_PTR(-EINVAL);
}
@@ -4078,7 +4058,7 @@ static int raid10_start_reshape(struct mddev *mddev)
sector_t size = raid10_size(mddev, 0, 0);
if (size < mddev->array_sectors) {
spin_unlock_irq(&conf->device_lock);
- printk(KERN_ERR "md/raid10:%s: array size must be reduce before number of disks\n",
+ pr_err("%s: array size must be reduced before number of disks\n",
mdname(mddev));
return -EINVAL;
}
--
2.10.1

2016-10-06 09:51:12

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 50/54] md/raid10: Delete indentation for one jump label

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:07:35 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: labels should not be indented

Thus fix the affected source code place.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 0f2cb20..2181f53 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4559,7 +4559,7 @@ static int handle_reshape_read_error(struct mddev *mddev,
rcu_read_lock();
if (success)
break;
- failed:
+failed:
slot++;
if (slot >= conf->copies)
slot = 0;
--
2.10.1

2016-10-06 09:51:31

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 51/54] md/raid10: Adjust 22 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:36:43 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 43 ++++++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 2181f53..82d79f5 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -734,10 +734,10 @@ static struct md_rdev *read_balance(struct r10conf *conf,
continue;
disk = r10_bio->devs[slot].devnum;
rdev = rcu_dereference(conf->mirrors[disk].replacement);
- if (rdev == NULL || test_bit(Faulty, &rdev->flags) ||
+ if (!rdev || test_bit(Faulty, &rdev->flags) ||
r10_bio->devs[slot].addr + sectors > rdev->recovery_offset)
rdev = rcu_dereference(conf->mirrors[disk].rdev);
- if (rdev == NULL ||
+ if (!rdev ||
test_bit(Faulty, &rdev->flags))
continue;
if (!test_bit(In_sync, &rdev->flags) &&
@@ -1386,7 +1386,8 @@ static void __make_request(struct mddev *mddev, struct bio *bio)

if (r10_bio->devs[i].repl_bio) {
struct md_rdev *rdev = conf->mirrors[d].replacement;
- if (rdev == NULL) {
+
+ if (!rdev) {
/* Replacement just got moved to main 'rdev' */
smp_mb();
rdev = conf->mirrors[d].rdev;
@@ -1701,7 +1702,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
first = last = rdev->raid_disk;

if (rdev->saved_raid_disk >= first &&
- conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
+ !conf->mirrors[rdev->saved_raid_disk].rdev)
mirror = rdev->saved_raid_disk;
else
mirror = first;
@@ -1711,7 +1712,7 @@ static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
continue;
if (p->rdev) {
if (!test_bit(WantReplacement, &p->rdev->flags) ||
- p->replacement != NULL)
+ p->replacement)
continue;
clear_bit(In_sync, &rdev->flags);
set_bit(Replacement, &rdev->flags);
@@ -1849,7 +1850,7 @@ static void end_sync_request(struct r10bio *r10_bio)
struct mddev *mddev = r10_bio->mddev;

while (atomic_dec_and_test(&r10_bio->remaining)) {
- if (r10_bio->master_bio == NULL) {
+ if (!r10_bio->master_bio) {
/* the primary of several recovery bios */
sector_t s = r10_bio->sectors;
if (test_bit(R10BIO_MadeGood, &r10_bio->state) ||
@@ -2515,7 +2516,7 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)

read_more:
rdev = read_balance(conf, r10_bio, &max_sectors);
- if (rdev == NULL) {
+ if (!rdev) {
pr_alert("%s: %s: unrecoverable I/O read error for block %llu\n",
mdname(mddev), b,
(unsigned long long)r10_bio->sector);
@@ -2587,7 +2588,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
for (m = 0; m < conf->copies; m++) {
int dev = r10_bio->devs[m].devnum;
rdev = conf->mirrors[dev].rdev;
- if (r10_bio->devs[m].bio == NULL)
+ if (!r10_bio->devs[m].bio)
continue;
if (!r10_bio->devs[m].bio->bi_error) {
rdev_clear_badblocks(
@@ -2602,7 +2603,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
md_error(conf->mddev, rdev);
}
rdev = conf->mirrors[dev].replacement;
- if (r10_bio->devs[m].repl_bio == NULL)
+ if (!r10_bio->devs[m].repl_bio)
continue;

if (!r10_bio->devs[m].repl_bio->bi_error) {
@@ -2631,7 +2632,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
r10_bio->devs[m].addr,
r10_bio->sectors, 0);
rdev_dec_pending(rdev, conf->mddev);
- } else if (bio != NULL && bio->bi_error) {
+ } else if (bio && bio->bi_error) {
fail = true;
if (!narrow_write_error(r10_bio, m)) {
md_error(conf->mddev, rdev);
@@ -2816,7 +2817,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
* Allow skipping a full rebuild for incremental assembly
* of a clean array, like RAID1 does.
*/
- if (mddev->bitmap == NULL &&
+ if (!mddev->bitmap &&
mddev->recovery_cp == MaxSector &&
mddev->reshape_position == MaxSector &&
!test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
@@ -2945,10 +2946,10 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
mrdev = rcu_dereference(mirror->rdev);
mreplace = rcu_dereference(mirror->replacement);

- if ((mrdev == NULL ||
+ if ((!mrdev ||
test_bit(Faulty, &mrdev->flags) ||
test_bit(In_sync, &mrdev->flags)) &&
- (mreplace == NULL ||
+ (!mreplace ||
test_bit(Faulty, &mreplace->flags))) {
rcu_read_unlock();
continue;
@@ -2976,7 +2977,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
if (sync_blocks < max_sync)
max_sync = sync_blocks;
if (!must_sync &&
- mreplace == NULL &&
+ !mreplace &&
!conf->fullsync) {
/* yep, skip the sync_blocks here, but don't assume
* that there will never be anything to do here
@@ -3011,7 +3012,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
for (j = 0; j < conf->geo.raid_disks; j++) {
struct md_rdev *rdev = rcu_dereference(
conf->mirrors[j].rdev);
- if (rdev == NULL || test_bit(Faulty, &rdev->flags)) {
+ if (!rdev || test_bit(Faulty, &rdev->flags)) {
still_degraded = 1;
break;
}
@@ -3099,7 +3100,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
* this comment keeps human reviewers
* happy.
*/
- if (mreplace == NULL || bio == NULL ||
+ if (!mreplace || !bio ||
test_bit(Faulty, &mreplace->flags))
break;
bio_reset(bio);
@@ -3161,7 +3162,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
if (mreplace)
rdev_dec_pending(mreplace, mddev);
}
- if (biolist == NULL) {
+ if (!biolist) {
while (r10_bio) {
struct r10bio *rb2 = r10_bio;
r10_bio = (struct r10bio*) rb2->master_bio;
@@ -3214,7 +3215,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
bio->bi_error = -EIO;
rcu_read_lock();
rdev = rcu_dereference(conf->mirrors[d].rdev);
- if (rdev == NULL || test_bit(Faulty, &rdev->flags)) {
+ if (!rdev || test_bit(Faulty, &rdev->flags)) {
rcu_read_unlock();
continue;
}
@@ -3243,7 +3244,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
count++;

rdev = rcu_dereference(conf->mirrors[d].replacement);
- if (rdev == NULL || test_bit(Faulty, &rdev->flags)) {
+ if (!rdev || test_bit(Faulty, &rdev->flags)) {
rcu_read_unlock();
continue;
}
@@ -3565,7 +3566,7 @@ static int raid10_run(struct mddev *mddev)
int first = 1;
bool discard_supported = false;

- if (mddev->private == NULL) {
+ if (!mddev->private) {
conf = setup_conf(mddev);
if (IS_ERR(conf))
return PTR_ERR(conf);
@@ -4542,7 +4543,7 @@ static int handle_reshape_read_error(struct mddev *mddev,
int d = r10b->devs[slot].devnum;
struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev);
sector_t addr;
- if (rdev == NULL ||
+ if (!rdev ||
test_bit(Faulty, &rdev->flags) ||
!test_bit(In_sync, &rdev->flags))
goto failed;
--
2.10.1

2016-10-06 09:52:29

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 52/54] md/raid10: Replace a seq_printf() call by seq_puts() in raid10_status()

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 21:41:09 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 82d79f5..554b6d2 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1502,7 +1502,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)
seq_printf(seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf(seq, "]");
+ seq_puts(seq, "]");
}

/* check if there are enough drives for
--
2.10.1

2016-10-06 09:54:00

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 53/54] md/raid10: Delete two unwanted spaces behind asterisks

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 22:02:18 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: "foo * bar" should be "foo *bar"

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 554b6d2..09c0e2f 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -107,7 +107,7 @@ static void reshape_request_write(struct mddev *mddev, struct r10bio *r10_bio);
static void end_reshape_write(struct bio *bio);
static void end_reshape(struct r10conf *conf);

-static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data)
+static void *r10bio_pool_alloc(gfp_t gfp_flags, void *data)
{
struct r10conf *conf = data;
int size = offsetof(struct r10bio, devs[conf->copies]);
@@ -137,7 +137,7 @@ static void r10bio_pool_free(void *r10_bio, void *data)
* one for write (we recover only one drive per r10buf)
*
*/
-static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
+static void *r10buf_pool_alloc(gfp_t gfp_flags, void *data)
{
struct r10conf *conf = data;
struct page *page;
--
2.10.1

2016-10-06 09:55:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 54/54] md/raid10: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Wed, 5 Oct 2016 22:22:14 +0200

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid10.c | 71 +++++++++++++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 09c0e2f..786992c 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -224,7 +224,7 @@ static void r10buf_pool_free(void *__r10_bio, void *data)
struct r10bio *r10bio = __r10_bio;
int j;

- for (j=0; j < conf->copies; j++) {
+ for (j = 0; j < conf->copies; j++) {
struct bio *bio = r10bio->devs[j].bio;
if (bio) {
for (i = 0; i < RESYNC_PAGES; i++) {
@@ -553,7 +553,7 @@ static void raid10_end_write_request(struct bio *bio)

static void __raid10_find_phys(struct geom *geo, struct r10bio *r10bio)
{
- int n,f;
+ int n, f;
sector_t sector;
sector_t chunk;
sector_t stripe;
@@ -1937,7 +1937,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
atomic_set(&r10_bio->remaining, 1);

/* find the first device with a block */
- for (i=0; i<conf->copies; i++)
+ for (i = 0; i < conf->copies; i++)
if (!r10_bio->devs[i].bio->bi_error)
break;

@@ -1951,7 +1951,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)

vcnt = (r10_bio->sectors + (PAGE_SIZE >> 9) - 1) >> (PAGE_SHIFT - 9);
/* now find blocks with errors */
- for (i=0 ; i < conf->copies ; i++) {
+ for (i = 0; i < conf->copies; i++) {
int j, d;

tbio = r10_bio->devs[i].bio;
@@ -2236,7 +2236,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
{
int sect = 0; /* Offset from r10_bio->sector */
int sectors = r10_bio->sectors;
- struct md_rdev*rdev;
+ struct md_rdev *rdev;
int max_read_errors = atomic_read(&mddev->max_corr_read_errors);
int d = r10_bio->devs[r10_bio->read_slot].devnum;

@@ -2265,7 +2265,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
return;
}

- while(sectors) {
+ while (sectors) {
int s = sectors;
int sl = r10_bio->read_slot;
int success = 0;
@@ -2331,7 +2331,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
while (sl != r10_bio->read_slot) {
char b[BDEVNAME_SIZE];

- if (sl==0)
+ if (sl == 0)
sl = conf->copies;
sl--;
d = r10_bio->devs[sl].devnum;
@@ -2368,7 +2368,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
while (sl != r10_bio->read_slot) {
char b[BDEVNAME_SIZE];

- if (sl==0)
+ if (sl == 0)
sl = conf->copies;
sl--;
d = r10_bio->devs[sl].devnum;
@@ -2996,7 +2996,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
raise_barrier(conf, rb2 != NULL);
atomic_set(&r10_bio->remaining, 0);

- r10_bio->master_bio = (struct bio*)rb2;
+ r10_bio->master_bio = (struct bio *)rb2;
if (rb2)
atomic_inc(&rb2->remaining);
r10_bio->mddev = mddev;
@@ -3022,7 +3022,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
&sync_blocks, still_degraded);

any_working = 0;
- for (j=0; j<conf->copies;j++) {
+ for (j = 0; j < conf->copies; j++) {
int k;
int d = r10_bio->devs[j].devnum;
sector_t from_addr, to_addr;
@@ -3063,7 +3063,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
atomic_inc(&rdev->nr_pending);
/* and we write to 'i' (if not in_sync) */

- for (k=0; k<conf->copies; k++)
+ for (k = 0; k < conf->copies; k++)
if (r10_bio->devs[k].devnum == i)
break;
BUG_ON(k == conf->copies);
@@ -3165,7 +3165,8 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
if (!biolist) {
while (r10_bio) {
struct r10bio *rb2 = r10_bio;
- r10_bio = (struct r10bio*) rb2->master_bio;
+
+ r10_bio = (struct r10bio *) rb2->master_bio;
rb2->master_bio = NULL;
put_buf(rb2);
}
@@ -3268,7 +3269,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
}

if (count < 2) {
- for (i=0; i<conf->copies; i++) {
+ for (i = 0; i < conf->copies; i++) {
int d = r10_bio->devs[i].devnum;
if (r10_bio->devs[i].bio->bi_end_io)
rdev_dec_pending(conf->mirrors[d].rdev,
@@ -3295,7 +3296,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
len = (max_sector - sector_nr) << 9;
if (len == 0)
break;
- for (bio= biolist ; bio ; bio=bio->bi_next) {
+ for (bio = biolist; bio; bio = bio->bi_next) {
struct bio *bio2;
page = bio->bi_io_vec[bio->bi_vcnt].bv_page;
if (bio_add_page(bio, page, len, 0))
@@ -3765,7 +3766,7 @@ static void raid10_quiesce(struct mddev *mddev, int state)
{
struct r10conf *conf = mddev->private;

- switch(state) {
+ switch (state) {
case 1:
raise_barrier(conf, 0);
break;
@@ -4658,26 +4659,26 @@ static void raid10_finish_reshape(struct mddev *mddev)
}

static struct md_personality raid10_personality = {
- .name = "raid10",
- .level = 10,
- .owner = THIS_MODULE,
- .make_request = raid10_make_request,
- .run = raid10_run,
- .free = raid10_free,
- .status = raid10_status,
- .error_handler = raid10_error,
- .hot_add_disk = raid10_add_disk,
- .hot_remove_disk= raid10_remove_disk,
- .spare_active = raid10_spare_active,
- .sync_request = raid10_sync_request,
- .quiesce = raid10_quiesce,
- .size = raid10_size,
- .resize = raid10_resize,
- .takeover = raid10_takeover,
- .check_reshape = raid10_check_reshape,
- .start_reshape = raid10_start_reshape,
- .finish_reshape = raid10_finish_reshape,
- .congested = raid10_congested,
+ .name = "raid10",
+ .level = 10,
+ .owner = THIS_MODULE,
+ .make_request = raid10_make_request,
+ .run = raid10_run,
+ .free = raid10_free,
+ .status = raid10_status,
+ .error_handler = raid10_error,
+ .hot_add_disk = raid10_add_disk,
+ .hot_remove_disk = raid10_remove_disk,
+ .spare_active = raid10_spare_active,
+ .sync_request = raid10_sync_request,
+ .quiesce = raid10_quiesce,
+ .size = raid10_size,
+ .resize = raid10_resize,
+ .takeover = raid10_takeover,
+ .check_reshape = raid10_check_reshape,
+ .start_reshape = raid10_start_reshape,
+ .finish_reshape = raid10_finish_reshape,
+ .congested = raid10_congested,
};

static int __init raid_init(void)
--
2.10.1

2016-10-06 10:08:03

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Fine-tuning for several function implementations

> This is not fine tuning but a waste of everyones time.

Does any of the published 54 update steps contain changes
which you might find also worthwhile for the affected source files
so that the shown software situation can be improved further?

Regards,
Markus

2016-10-06 15:16:41

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2 13/15] md-cluster: Less function calls in join() after error detection

From: Markus Elfring <[email protected]>
Date: Thu, 6 Oct 2016 16:48:51 +0200

A few resource release functions were called in some cases
by the join() function during error handling
even if the passed data structure member contained a null pointer.

* Adjust jump targets according to the Linux coding style convention.

* Delete a repeated check which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---

v2: Julia Lawall wrote on 2016-10-01 at 19:07:
> Please check lines 919 and 920.
>
> julia
>
> ---------- Forwarded message ----------
> Date: Sun, 2 Oct 2016 01:03:19 +0800
> From: kbuild test robot <[email protected]>
> To: [email protected]
> Cc: Julia Lawall <[email protected]>
> Subject:
> [linux-review:SF-Markus-Elfring/md-cluster-Fine-tuning-for-ten-function-impl
> ementations/20161001-230311 13/15] drivers/md/md-cluster.c:920:23-28: ERROR:
> reference preceded by free on line 919
>
> CC: [email protected]
> TO: Markus Elfring <[email protected]>
> CC: 0day robot <[email protected]>
>
> tree: https://github.com/0day-ci/linux SF-Markus-Elfring/md-cluster-Fine-tuning-for-ten-function-implementations/20161001-230311
> head: 7b2084c76eb1c60f2ae5c2778470124b5b68e9fb
> commit: 6955234a0083a739f595e753e89ba7b5b3962f50 [13/15] md-cluster: Less function calls in join() after error detection
> :::::: branch date: 2 hours ago
> :::::: commit date: 2 hours ago
>
>>> drivers/md/md-cluster.c:920:23-28: ERROR: reference preceded by free on line 919
>
> git remote add linux-review https://github.com/0day-ci/linux
> git remote update linux-review
> git checkout 6955234a0083a739f595e753e89ba7b5b3962f50
> vim +920 drivers/md/md-cluster.c
>
> 6955234a Markus Elfring 2016-10-01 913 lockres_free(cinfo->message_lockres);
> 6955234a Markus Elfring 2016-10-01 914 unregister_recv:
> 6955234a Markus Elfring 2016-10-01 915 md_unregister_thread(&cinfo->recv_thread);
> 6955234a Markus Elfring 2016-10-01 916 release_lockspace:
> c4ce867f Goldwyn Rodrigues 2014-03-29 917 dlm_release_lockspace(cinfo->lockspace, 2);
> 6955234a Markus Elfring 2016-10-01 918 free_cluster_info:
> c4ce867f Goldwyn Rodrigues 2014-03-29 @919 kfree(cinfo);
> 6955234a Markus Elfring 2016-10-01 @920 md_unregister_thread(&cinfo->recovery_thread);
> 6955234a Markus Elfring 2016-10-01 921 mddev->cluster_info = NULL;
> c4ce867f Goldwyn Rodrigues 2014-03-29 922 return ret;
> edb39c9d Goldwyn Rodrigues 2014-03-29 923 }
>
> ---
> 0-DAY kernel test infrastructure Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all Intel Corporation


This automatic notification pointed out that I should have switched the order
of calls for the functions "kfree" and "md_unregister_thread".
I hope that my second approach could be integrated into another
source code repository.


drivers/md/md-cluster.c | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index e1ebcc4..e60511a 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -837,39 +837,39 @@ static int join(struct mddev *mddev, int nodes)
DLM_LSFL_FS, LVB_SIZE,
&md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);
if (ret)
- goto err;
+ goto unregister_recovery_thread;
wait_for_completion(&cinfo->completion);
if (nodes < cinfo->slot_number) {
pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).",
cinfo->slot_number, nodes);
ret = -ERANGE;
- goto err;
+ goto release_lockspace;
}
/* Initiate the communication resources */
ret = -ENOMEM;
cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
if (!cinfo->recv_thread)
- goto err;
+ goto release_lockspace;
cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
if (!cinfo->message_lockres)
- goto err;
+ goto unregister_recv;
cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0);
if (!cinfo->token_lockres)
- goto err;
+ goto free_message;
cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0);
if (!cinfo->no_new_dev_lockres)
- goto err;
+ goto free_token;

ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
if (ret) {
ret = -EAGAIN;
pr_err("md-cluster: can't join cluster to avoid lock issue\n");
- goto err;
+ goto free_no_new_dev;
}
cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0);
if (!cinfo->ack_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_no_new_dev;
}
/* get sync CR lock on ACK. */
if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR))
@@ -886,34 +886,39 @@ static int join(struct mddev *mddev, int nodes)
cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1);
if (!cinfo->bitmap_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_ack;
}
if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) {
pr_err("Failed to get bitmap lock\n");
ret = -EINVAL;
- goto err;
+ goto free_bitmap;
}

cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0);
if (!cinfo->resync_lockres) {
ret = -ENOMEM;
- goto err;
+ goto free_bitmap;
}

return 0;
-err:
- md_unregister_thread(&cinfo->recovery_thread);
- md_unregister_thread(&cinfo->recv_thread);
- lockres_free(cinfo->message_lockres);
- lockres_free(cinfo->token_lockres);
+free_bitmap:
+ lockres_free(cinfo->bitmap_lockres);
+free_ack:
lockres_free(cinfo->ack_lockres);
+free_no_new_dev:
lockres_free(cinfo->no_new_dev_lockres);
- lockres_free(cinfo->resync_lockres);
- lockres_free(cinfo->bitmap_lockres);
- if (cinfo->lockspace)
- dlm_release_lockspace(cinfo->lockspace, 2);
- mddev->cluster_info = NULL;
+free_token:
+ lockres_free(cinfo->token_lockres);
+free_message:
+ lockres_free(cinfo->message_lockres);
+unregister_recv:
+ md_unregister_thread(&cinfo->recv_thread);
+release_lockspace:
+ dlm_release_lockspace(cinfo->lockspace, 2);
+unregister_recovery_thread:
+ md_unregister_thread(&cinfo->recovery_thread);
kfree(cinfo);
+ mddev->cluster_info = NULL;
return ret;
}

--
2.10.1

2016-10-06 16:33:58

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces

On Thu, 2016-10-06 at 11:49 +0200, SF Markus Elfring wrote:
[]
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 5119846..0f2cb20 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -18,6 +18,8 @@
> ? * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> ? */
> ?
> +#define MY_LOG_PREFIX KBUILD_MODNAME ": "
> +#define pr_fmt(fmt) MY_LOG_PREFIX fmt

Please just use

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

like the more than thousand other uses in the kernel.

2016-10-06 16:35:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

On Thu, 2016-10-06 at 11:37 +0200, SF Markus Elfring wrote:
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
[]
> @@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
> rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> }
> rcu_read_unlock();
> - seq_printf (seq, "]");
> + seq_puts(seq, "]");

seq_putc

2016-10-06 17:10:04

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

>> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> []
>> @@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
>> rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
>> }
>> rcu_read_unlock();
>> - seq_printf (seq, "]");
>> + seq_puts(seq, "]");
>
> seq_putc

Thanks for your update suggestion.

How do you think about the possibility that the script "checkpatch.pl" can also point
such a source code transformation out directly?
Would an additional check for the length of the passed string be useful in similar
use cases?

Regards,
Markus

2016-10-06 17:21:40

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces

>> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
>> index 5119846..0f2cb20 100644
>> --- a/drivers/md/raid10.c
>> +++ b/drivers/md/raid10.c
>> @@ -18,6 +18,8 @@
>> * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>> */
>>
>> +#define MY_LOG_PREFIX KBUILD_MODNAME ": "
>> +#define pr_fmt(fmt) MY_LOG_PREFIX fmt
>
> Please just use
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> like the more than thousand other uses in the kernel.

Thanks for your suggestion.

I got the impression that the omission of a macro like "MY_LOG_PREFIX"
would not really work for the suggested source code transformation so far.

How should a multiline log message be achieved as it was constructed
in the function "raid10_error" (for example)?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?id=c802e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589

Regards,
Markus

2016-10-06 17:36:58

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

On Thu, 2016-10-06 at 19:09 +0200, SF Markus Elfring wrote:
> > > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> > []
> > > @@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
> > > ? rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> > > ? }
> > > ? rcu_read_unlock();
> > > - seq_printf (seq, "]");
> > > + seq_puts(seq, "]");
> > seq_putc
> How do you think about the possibility that the script "checkpatch.pl" can also point
> such a source code transformation out directly?

Why don't _you_ try to implement that in checkpatch instead?

2016-10-06 17:39:21

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 49/54] md/raid10: Replace printk() calls by the usage of higher level interfaces

On Thu, 2016-10-06 at 19:20 +0200, SF Markus Elfring wrote:
> How should a multiline log message be achieved as it was constructed
> in the function "raid10_error" (for example)?
> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?id=c802e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589

As two individual calls to pr_alert

2016-10-06 17:50:26

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

>>>> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
>>> []
>>>> @@ -7044,7 +7044,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
>>>> rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
>>>> }
>>>> rcu_read_unlock();
>>>> - seq_printf (seq, "]");
>>>> + seq_puts(seq, "]");
>>> seq_putc
>> How do you think about the possibility that the script "checkpatch.pl" can also point
>> such a source code transformation out directly?
>
> Why don't _you_ try to implement that in checkpatch instead?

How are the chances that any other software developer would be quicker (than me) for such
an addition because of more practical knowledge for the programming language "Perl"?

Regards,
Markus

2016-10-06 17:52:01

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

On Thu, 2016-10-06 at 19:49 +0200, SF Markus Elfring wrote:
> > Why don't _you_ try to implement that in checkpatch instead?
> How are the chances that any other software developer would be quicker (than me) for such
> an addition because of more practical knowledge for the programming language "Perl"?

Extremely high.

What are the chances you can add useful attributes to your skilz?

2016-10-06 18:06:50

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid10: Replace printk() calls by the usage of higher level interfaces

>> How should a multiline log message be achieved as it was constructed
>> in the function "raid10_error" (for example)?
>> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/md/raid10.c?id=c802e87fbe2d4dd58982d01b3c39bc5a781223aa#n1589
>
> As two individual calls to pr_alert

I know also such an approach.

Would it be nicer if a single call will be sufficient for such a log message?

Can an idea picked up which was discussed for the update suggestion
"[PATCH 4/4] Input-gameport: Replace some printk() calls by pr_info() in joydump_connect()"
for a moment (on 2016-09-24)?
https://lkml.kernel.org/r/<[email protected]>
https://lkml.org/lkml/2016/9/24/149

Regards,
Markus

2016-10-06 18:18:18

by Joe Perches

[permalink] [raw]
Subject: Re: md/raid10: Replace printk() calls by the usage of higher level interfaces

On Thu, 2016-10-06 at 20:04 +0200, SF Markus Elfring wrote:
> Would it be nicer if a single call will be sufficient for such a log message?
>
> Can an idea picked up which was discussed for the update suggestion
> "[PATCH 4/4] Input-gameport: Replace some printk() calls by pr_info() in joydump_connect()"
> for a moment (on 2016-09-24)?
> https://lkml.kernel.org/r/<[email protected]>;
> https://lkml.org/lkml/2016/9/24/149

That'd be great.
Pease come back only after you've implemented that.

2016-10-06 18:23:22

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

>>> Why don't _you_ try to implement that in checkpatch instead?
>> How are the chances that any other software developer would be quicker (than me) for such
>> an addition because of more practical knowledge for the programming language "Perl"?
>
> Extremely high.

Thanks for this feedback.


> What are the chances you can add useful attributes to your skilz?

Unfortunately, "Perl" does not belong to a favourite in my current collection
of programming languages I learned through my software development activities.
I imagine that I would prefer to improve other Linux software modules
for a while instead?

Would it be interesting if the Coccinelle software could help a bit more with
corresponding semantic patches?

Regards,
Markus

2016-10-06 18:35:05

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid10: Replace printk() calls by the usage of higher level interfaces

>> Would it be nicer if a single call will be sufficient for such a log message?
>>
>> Can an idea picked up which was discussed for the update suggestion
>> "[PATCH 4/4] Input-gameport: Replace some printk() calls by pr_info() in joydump_connect()"
>> for a moment (on 2016-09-24)?
>> https://lkml.kernel.org/r/<[email protected]>;
>> https://lkml.org/lkml/2016/9/24/149
>
> That'd be great.
> Pease come back only after you've implemented that.

Does this use case show another improvement opportunity for involved
software developers (besides me)?

Are there any more contributors around who would like to tackle such a challenge?

Regards,
Markus

2016-10-06 19:11:18

by Bernd Petrovitsch

[permalink] [raw]
Subject: Re: [PATCH 37/54] md/raid5: Replace a seq_printf() call by seq_puts() in raid5_status()

Hi all!

On Thu, 2016-10-06 at 19:49 +0200, SF Markus Elfring wrote:
> > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> > > > []
> > > > >
> > > > > @@ -7044,7 +7044,7 @@ static void raid5_status(struct
> > > > > seq_file *seq, struct mddev *mddev)
> > > > >      rdev && test_bit(In_sync, &rdev-
> > > > > >flags) ? "U" : "_");
> > > > >   }
> > > > >   rcu_read_unlock();
> > > > > - seq_printf (seq, "]");
> > > > > + seq_puts(seq, "]");
> > > > seq_putc
> > > How do you think about the possibility that the script
> > > "checkpatch.pl" can also point
> > > such a source code transformation out directly?
> >
> > Why don't _you_ try to implement that in checkpatch instead?
>
> How are the chances that any other software developer would be
> quicker (than me) for such
> an addition because of more practical knowledge for the programming
> language "Perl"?

The above is BTW a pretty simple thing and thus good for a learning
experience for regular expressions and copy-pasting a few lines in that
perl-script and editing them.

MfG,
Bernd

PS: Sry for the noise - it's somewhat OT here ....
--
Bernd Petrovitsch Email : [email protected]
LUGA : http://www.luga.at

2016-10-07 05:51:57

by Hannes Reinecke

[permalink] [raw]
Subject: Re: [PATCH 30/54] md/raid5: Delete two error messages for a failed memory allocation

On 10/06/2016 11:30 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Wed, 5 Oct 2016 09:43:40 +0200
>
> Omit extra messages for a memory allocation failure in this function.
>
> Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/md/raid5.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index d864871..ef180c0 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -6613,12 +6613,9 @@ static struct r5conf *setup_conf(struct mddev *mddev)
> memory = conf->min_nr_stripes * (sizeof(struct stripe_head) +
> max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
> atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS);
> - if (grow_stripes(conf, conf->min_nr_stripes)) {
> - printk(KERN_ERR
> - "md/raid:%s: couldn't allocate %dkB for buffers\n",
> - mdname(mddev), memory);
> + if (grow_stripes(conf, conf->min_nr_stripes))
> goto free_conf;
> - } else
> + else
> printk(KERN_INFO "md/raid:%s: allocated %dkB\n",
> mdname(mddev), memory);
> /*
> @@ -6640,12 +6637,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
>
> sprintf(pers_name, "raid%d", mddev->new_level);
> conf->thread = md_register_thread(raid5d, mddev, pers_name);
> - if (!conf->thread) {
> - printk(KERN_ERR
> - "md/raid:%s: couldn't allocate thread.\n",
> - mdname(mddev));
> + if (!conf->thread)
> goto free_conf;
> - }
>
> return conf;
> free_conf:
>
Actually I prefer having error messages, especially if you have several
possible failures all leading to the same return value.
Without it debugging becomes really hard.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

2016-10-07 07:48:17

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 15/15] md-cluster: Delete unnecessary braces in unlock_all_bitmaps()

On Sat, Oct 01, 2016 at 05:00:07PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 1 Oct 2016 16:15:55 +0200
>
> Do not use curly brackets at one source code place
> where a single statement should be sufficient.
>

The original style was correct and this is wrong. I have explained this
before.

regards,
dan carpenter

2016-10-07 07:54:47

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

On Thu, Oct 06, 2016 at 11:29:20AM +0200, Richard Weinberger wrote:
> On Thu, Oct 6, 2016 at 11:22 AM, SF Markus Elfring
> <[email protected]> wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Tue, 4 Oct 2016 21:46:18 +0200
> >
> > Replace the specification of a data structure by a pointer dereference
> > as the parameter for the operator "sizeof" to make the corresponding size
> > determination a bit safer.
>
> Isn't this pure matter of taste?
> Some developers prefer sizeof(*ptr) because it is easier to type, other
> developers prefer sizeof(struct foo) because you can determine the type
> at first sight and makes review more easy.

sizeof(*ptr) is more future proof and normally more obvious and easier
to review. That said, I've tried to tell Markus to only send bugfix
patches because these are a waste of time and regularly introduce bugs.

regards,
dan carpenter

2016-10-07 08:16:07

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

On 07.10.2016 09:53, Dan Carpenter wrote:
> On Thu, Oct 06, 2016 at 11:29:20AM +0200, Richard Weinberger wrote:
>> On Thu, Oct 6, 2016 at 11:22 AM, SF Markus Elfring
>> <[email protected]> wrote:
>>> From: Markus Elfring <[email protected]>
>>> Date: Tue, 4 Oct 2016 21:46:18 +0200
>>>
>>> Replace the specification of a data structure by a pointer dereference
>>> as the parameter for the operator "sizeof" to make the corresponding size
>>> determination a bit safer.
>>
>> Isn't this pure matter of taste?
>> Some developers prefer sizeof(*ptr) because it is easier to type, other
>> developers prefer sizeof(struct foo) because you can determine the type
>> at first sight and makes review more easy.
>
> sizeof(*ptr) is more future proof and normally more obvious and easier
> to review.

Also a matter of taste.
See http://yarchive.net/comp/linux/struct_init.html

Thanks,
//richard

2016-10-07 08:37:43

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md-cluster: Delete unnecessary braces in unlock_all_bitmaps()

>> Do not use curly brackets at one source code place
>> where a single statement should be sufficient.
>
> The original style was correct and this is wrong. I have explained this before.

Did I change a bit too much in the proposed step according to the following
update suggestion?

elfring@Sonne:~/Projekte/Linux/next-patched> git checkout d6385db94196b253ae5eb3678fa95cdf1f839fcc && scripts/checkpatch.pl --types BRACES -f drivers/md/md-cluster.c

WARNING: braces {} are not necessary for single statement blocks
#1228: FILE: drivers/md/md-cluster.c:1228:
+ if (cinfo->other_bitmap_lockres[i]) {
+ lockres_free(cinfo->other_bitmap_lockres[i]);
+ }



How do you think about to adjust this source code place a bit?

Regards,
Markus

2016-10-07 08:54:04

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

>>> Replace the specification of a data structure by a pointer dereference
>>> as the parameter for the operator "sizeof" to make the corresponding size
>>> determination a bit safer.
>>
>> Isn't this pure matter of taste?
>> Some developers prefer sizeof(*ptr) because it is easier to type, other
>> developers prefer sizeof(struct foo) because you can determine the type
>> at first sight and makes review more easy.
>
> sizeof(*ptr) is more future proof and normally more obvious and easier
> to review.

Is it interesting to see how different the software development opinions
can be for such an implementation detail?


> That said, I've tried to tell Markus to only send bugfix patches

Can any deviations from the Linux coding style become "bugs" also in
your view of the software situation?


> because these are a waste of time

How do you value compliance with coding styles?


> and regularly introduce bugs.

Really?

Would you like to discuss concrete incidents any further?

Regards,
Markus

2016-10-07 09:07:33

by Richard Weinberger

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

On 07.10.2016 10:53, SF Markus Elfring wrote:
>>>> Replace the specification of a data structure by a pointer dereference
>>>> as the parameter for the operator "sizeof" to make the corresponding size
>>>> determination a bit safer.
>>>
>>> Isn't this pure matter of taste?
>>> Some developers prefer sizeof(*ptr) because it is easier to type, other
>>> developers prefer sizeof(struct foo) because you can determine the type
>>> at first sight and makes review more easy.
>>
>> sizeof(*ptr) is more future proof and normally more obvious and easier
>> to review.
>
> Is it interesting to see how different the software development opinions
> can be for such an implementation detail?
>
>
>> That said, I've tried to tell Markus to only send bugfix patches
>
> Can any deviations from the Linux coding style become "bugs" also in
> your view of the software situation?
>
>
>> because these are a waste of time
>
> How do you value compliance with coding styles?

Just stop sending these kind of patches, *please*.
Linux has tons of issues, fixes for real problems are very welcome.
But coding style bike shedding is just a waste of time.

Thanks,
//richard

2016-10-07 10:57:42

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

> Linux has tons of issues, fixes for real problems are very welcome.

Is a spectrum of software improvements to reconsider there?


> But coding style bike shedding is just a waste of time.

Why do various software developers bother about coding style specifications
at all then?

Regards,
Markus

2016-10-07 11:52:42

by Austin S Hemmelgarn

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

On 2016-10-07 06:50, SF Markus Elfring wrote:
>> Linux has tons of issues, fixes for real problems are very welcome.
>
> Is a spectrum of software improvements to reconsider there?
>
>
>> But coding style bike shedding is just a waste of time.
>
> Why do various software developers bother about coding style specifications
> at all then?
Coding style is important, but patches that just fix coding style are a
bad thing because they break things like `git blame` and run the risk of
introducing new bugs without any net benefit to end users. This goes
double for code you don't actually work on regularly or don't completely
understand.

2016-10-07 13:21:27

by walter harms

[permalink] [raw]
Subject: Re: md-cluster: Delete unnecessary braces in unlock_all_bitmaps()



Am 07.10.2016 10:37, schrieb SF Markus Elfring:
>>> Do not use curly brackets at one source code place
>>> where a single statement should be sufficient.
>>
>> The original style was correct and this is wrong. I have explained this before.
>
> Did I change a bit too much in the proposed step according to the following
> update suggestion?
>
> elfring@Sonne:~/Projekte/Linux/next-patched> git checkout d6385db94196b253ae5eb3678fa95cdf1f839fcc && scripts/checkpatch.pl --types BRACES -f drivers/md/md-cluster.c
> …
> WARNING: braces {} are not necessary for single statement blocks
> #1228: FILE: drivers/md/md-cluster.c:1228:
> + if (cinfo->other_bitmap_lockres[i]) {
> + lockres_free(cinfo->other_bitmap_lockres[i]);
> + }
> …
>
>
> How do you think about to adjust this source code place a bit?
>

perhaps we can agree to delete the if() block ?

static void lockres_free(struct dlm_lock_resource *res)
{
int ret;

if (!res)
return;

....


@marcus: is can not send mail to you sf.net adresse because sf.net
mark my domain als spam (note: nobody else does)

re,
wh


2016-10-07 15:28:01

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

>> Why do various software developers bother about coding style specifications
>> at all then?
> Coding style is important,

Thanks that you "dare" to express also such an opinion.


> but patches that just fix coding style are a bad thing

When you find such a change opportunity so "bad", are there any circumstances
left over where you would dare to touch the corresponding source code line.


> because they break things like `git blame`

I follow your concern to some degree.

But can this argument evolve against a lot of changes generally?


> and run the risk of introducing new bugs

Did this really "happen" because of an update suggestion for this software module?


> without any net benefit to end users.

Can the proposed adjustment help to make a function like "setup_conf"
a bit more robust (together with related update steps) so that an improved
coding style compliance will hopefully influence the error probability
in positive ways?


> This goes double for code you don't actually work on regularly
> or don't completely understand.

How does such a kind of general feedback fit to the shown change
possibilities in this patch series?

Do you reject this update step?

Regards,
Markus

2016-10-07 15:38:11

by Jiri Kosina

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

On Fri, 7 Oct 2016, SF Markus Elfring wrote:

> > but patches that just fix coding style are a bad thing
>
> When you find such a change opportunity so "bad", are there any
> circumstances left over where you would dare to touch the corresponding
> source code line.

If you actually rewrite the code or fix some real bug there.

> > because they break things like `git blame`
>
> I follow your concern to some degree.
>
> But can this argument evolve against a lot of changes generally?

If I have to reiterate git blame multiple times just because of whitespace
or codingstyle changes, it's a pure waste of my time.

If I have to reiterate git blame multiple times to skip actual real
changes, I have no other option than to live with that (because there was
an actual functional reason for the change).

--
Jiri Kosina
SUSE Labs

2016-10-07 16:39:41

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

>>> but patches that just fix coding style are a bad thing
>>
>> When you find such a change opportunity so "bad", are there any
>> circumstances left over where you would dare to touch the corresponding
>> source code line.
>
> If you actually rewrite the code or fix some real bug there.

Do the proposed update steps 12 - 16 for the function "setup_conf"
(in this software module) fit to your condition?

Do you reject this update step?

Regards,
Markus

2016-10-07 19:44:41

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] [media] dvb-tc90522: Fine-tuning for two function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:38:12 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use kmalloc_array()
Rename a jump label

drivers/media/dvb-frontends/tc90522.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

--
2.10.1

2016-10-07 19:45:33

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] [media] dvb-tc90522: Use kmalloc_array() in tc90522_master_xfer()

From: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:07:43 +0200

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/dvb-frontends/tc90522.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
index 31cd325..c2d45f0 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -656,7 +656,7 @@ tc90522_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
for (i = 0; i < num; i++)
if (msgs[i].flags & I2C_M_RD)
rd_num++;
- new_msgs = kmalloc(sizeof(*new_msgs) * (num + rd_num), GFP_KERNEL);
+ new_msgs = kmalloc_array(num + rd_num, sizeof(*new_msgs), GFP_KERNEL);
if (!new_msgs)
return -ENOMEM;

--
2.10.1

2016-10-07 19:46:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] [media] dvb-tc90522: Rename a jump label in tc90522_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 7 Oct 2016 21:13:57 +0200

Adjust a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/dvb-frontends/tc90522.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
index c2d45f0..4687e15 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -794,14 +794,13 @@ static int tc90522_probe(struct i2c_client *client,
i2c_set_adapdata(adap, state);
ret = i2c_add_adapter(adap);
if (ret < 0)
- goto err;
+ goto free_state;
cfg->tuner_i2c = state->cfg.tuner_i2c = adap;

i2c_set_clientdata(client, &state->cfg);
dev_info(&client->dev, "Toshiba TC90522 attached.\n");
return 0;
-
-err:
+free_state:
kfree(state);
return ret;
}
--
2.10.1

2016-10-08 11:58:01

by walter harms

[permalink] [raw]
Subject: Re: [PATCH 2/2] [media] dvb-tc90522: Rename a jump label in tc90522_probe()



Am 07.10.2016 21:46, schrieb SF Markus Elfring:
> From: Markus Elfring <[email protected]>
> Date: Fri, 7 Oct 2016 21:13:57 +0200
>
> Adjust a jump label according to the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/dvb-frontends/tc90522.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
> index c2d45f0..4687e15 100644
> --- a/drivers/media/dvb-frontends/tc90522.c
> +++ b/drivers/media/dvb-frontends/tc90522.c
> @@ -794,14 +794,13 @@ static int tc90522_probe(struct i2c_client *client,
> i2c_set_adapdata(adap, state);
> ret = i2c_add_adapter(adap);
> if (ret < 0)
> - goto err;
> + goto free_state;
> cfg->tuner_i2c = state->cfg.tuner_i2c = adap;
>
> i2c_set_clientdata(client, &state->cfg);
> dev_info(&client->dev, "Toshiba TC90522 attached.\n");
> return 0;
> -
> -err:
> +free_state:
> kfree(state);
> return ret;
> }

there is only one user, IMHO this can be moved to the if block.

re,
wh

2016-10-10 11:17:54

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

On Thu, Oct 06, 2016 at 11:29:20AM +0200, Richard Weinberger wrote:
> On Thu, Oct 6, 2016 at 11:22 AM, SF Markus Elfring
> <[email protected]> wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Tue, 4 Oct 2016 21:46:18 +0200
> >
> > Replace the specification of a data structure by a pointer dereference
> > as the parameter for the operator "sizeof" to make the corresponding size
> > determination a bit safer.
>
> Isn't this pure matter of taste?
> Some developers prefer sizeof(*ptr) because it is easier to type, other
> developers prefer sizeof(struct foo) because you can determine the type
> at first sight and makes review more easy.
>

I am ignoring Markus patches and have told him that he should focus on
bug fixes. These patches don't add any value and regularly introduce
bugs.

That said, "sizeof(*ptr)" is sort of official style. It's slightly
more obvious and easier to review because all the information you need
is on that one line. Also if we change the datatype of ptr then that
format is slightly more future proof.

regards,
dan carpenter

2016-10-10 12:29:18

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

> I am ignoring Markus patches

It's a pity that you chose such a reaction.


> and have told him that he should focus on bug fixes.

I find that I suggest to improve something. Could you admit a few times
that I found a "bug" you care also about at other source code places?


> These patches don't add any value

Can it be that you express a lower value for the Linux coding style here
than desired as there might be other concerns behind such negative feedback?


> and regularly introduce bugs.

How do you think about to discuss corresponding facts further?


> That said, "sizeof(*ptr)" is sort of official style.

When this implementation detail is so official, I wonder then why some
software developers can become "special" about the proposed update step
like for this module.

Regards,
Markus

2016-10-10 13:07:26

by Jes Sorensen

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

SF Markus Elfring <[email protected]> writes:
>>>> Replace the specification of a data structure by a pointer dereference
>>>> as the parameter for the operator "sizeof" to make the corresponding size
>>>> determination a bit safer.
>>>
>>> Isn't this pure matter of taste?
>>> Some developers prefer sizeof(*ptr) because it is easier to type, other
>>> developers prefer sizeof(struct foo) because you can determine the type
>>> at first sight and makes review more easy.
>>
>> sizeof(*ptr) is more future proof and normally more obvious and easier
>> to review.
>
> Is it interesting to see how different the software development opinions
> can be for such an implementation detail?
>
>> That said, I've tried to tell Markus to only send bugfix patches
>
> Can any deviations from the Linux coding style become "bugs" also in
> your view of the software situation?
>
>> because these are a waste of time
>
> How do you value compliance with coding styles?

The Linux Coding Style is not a law, nor is it at all perfect. You
clearly misunderstood how Linux development work and you are doing a
great job wasting everyone's time with this patchset.

Jes

2016-10-10 13:11:02

by Jes Sorensen

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

Dan Carpenter <[email protected]> writes:
> On Thu, Oct 06, 2016 at 11:29:20AM +0200, Richard Weinberger wrote:
>> On Thu, Oct 6, 2016 at 11:22 AM, SF Markus Elfring
>> <[email protected]> wrote:
>> > From: Markus Elfring <[email protected]>
>> > Date: Tue, 4 Oct 2016 21:46:18 +0200
>> >
>> > Replace the specification of a data structure by a pointer dereference
>> > as the parameter for the operator "sizeof" to make the corresponding size
>> > determination a bit safer.
>>
>> Isn't this pure matter of taste?
>> Some developers prefer sizeof(*ptr) because it is easier to type, other
>> developers prefer sizeof(struct foo) because you can determine the type
>> at first sight and makes review more easy.
>
> sizeof(*ptr) is more future proof and normally more obvious and easier
> to review. That said, I've tried to tell Markus to only send bugfix
> patches because these are a waste of time and regularly introduce bugs.

This is totally a matter of taste. I for one find it way easier to
review something which says 'sizeof(struct ....)' because it stands out
more. I am curious what you mean by it being more future proof - if the
code says 'struct foo' in the sizeof argument, what is the problem?

The one area where there is a higher risk is if the type is changed, but
that is outweighed by the fact the spelled out version is easier to
review.

Jes

2016-10-10 13:11:31

by Jes Sorensen

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

SF Markus Elfring <[email protected]> writes:
>>>> but patches that just fix coding style are a bad thing
>>>
>>> When you find such a change opportunity so "bad", are there any
>>> circumstances left over where you would dare to touch the corresponding
>>> source code line.
>>
>> If you actually rewrite the code or fix some real bug there.
>
> Do the proposed update steps 12 - 16 for the function "setup_conf"
> (in this software module) fit to your condition?
>
> Do you reject this update step?

I do - those changes do nothing to improve the code and simply hides a
lot of history.

Jes

2016-10-10 13:21:50

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

>> How do you value compliance with coding styles?
>
> The Linux Coding Style is not a law,

How serious can such guidelines become for software developers?


> nor is it at all perfect.

I got a similar impression. But are there enough items where a mostly clear
guidance is specified?


> You clearly misunderstood how Linux development work

I got an other impression.


> and you are doing a great job wasting everyone's time with this patchset.

Would you like to reject any update steps for the affected source files
from this patch series?

Can it "accidentally" happen that some of them will be really worth
also for your precious software development attention?

Regards,
Markus

2016-10-10 14:00:42

by Bjørn Mork

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

Dan Carpenter <[email protected]> writes:

> I am ignoring Markus patches and have told him that he should focus on
> bug fixes. These patches don't add any value and regularly introduce
> bugs.

I think there should be a big fat warning in CodingStyle:

THIS DOCUMENT DOES NOT APPLY TO ANY EXISTING KERNEL CODE.


Preserving existing style is more important than any minor style issue
anyway. Style changes for the only purpose of style change should be
considered harmful and destructive behaviour. You'd think that is bloody
obvious, but evidently it isn't. Not only are the untested, buggy,
churning patches still being submitted - some of them are even applied!

Adding such a statement will not prevent style changes, even changes
to bring code more in line with CodingStyle, as long as the patches are
part of some work of substance. E.g. cleaning up before fixing bugs. If
you submit new code, then you can of course fix the style of any touched
context.

Oh well, I can dream..


Bjørn


2016-10-10 14:01:50

by Jes Sorensen

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

SF Markus Elfring <[email protected]> writes:
>>> How do you value compliance with coding styles?
>>
>> The Linux Coding Style is not a law,
>
> How serious can such guidelines become for software developers?
>
>> nor is it at all perfect.
>
> I got a similar impression. But are there enough items where a mostly clear
> guidance is specified?
>
>> You clearly misunderstood how Linux development work
>
> I got an other impression.
>
>> and you are doing a great job wasting everyone's time with this patchset.
>
> Would you like to reject any update steps for the affected source files
> from this patch series?
>
> Can it "accidentally" happen that some of them will be really worth
> also for your precious software development attention?

Given that none of your patches fix any real bugs and you do your best
to ignore any guidance you have been given, I do reject your entire
patchset and you can consider this a NACK for this entire series.

I get the impression you obtain your response to any email from M-x
doctor.

Jes

2016-10-10 14:22:06

by SF Markus Elfring

[permalink] [raw]
Subject: Re: md/raid1: Improve another size determination in setup_conf()

>> Can it "accidentally" happen that some of them will be really worth
>> also for your precious software development attention?
>
> Given that none of your patches fix any real bugs

Are there any ones which would eventually become "real" also for you?


> and you do your best to ignore any guidance you have been given,

I dare occasionally to find reasons out for a specific disagreement.


> I do reject your entire patchset and you can consider this a NACK for this entire series.

Thanks for your feedback.

I am still curious if any other software developers or source code reviewers
would dare to express an other opinion for one of the shown update possibilities.

Regards,
Markus

2016-10-11 06:21:15

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

Oops. I sent this email twice. Sorry, about that.

regards,
dan carpenter

2016-10-12 08:29:47

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

Compare:

foo = kmalloc(sizeof(*foo), GFP_KERNEL);

This says you are allocating enough space for foo. It can be reviewed
by looking at one line. If you change the type of foo it will still
work.

foo = kmalloc(sizeof(struct whatever), GFP_KERNEL);

There isn't enough information to say if this is correct. If you change
the type of foo then you have to update the allocation as well.

It's not a super common type of bug, but I see it occasionally.

regards,
dan carpenter

2016-10-12 12:19:00

by Jes Sorensen

[permalink] [raw]
Subject: Re: [PATCH 24/54] md/raid1: Improve another size determination in setup_conf()

Dan Carpenter <[email protected]> writes:
> Compare:
>
> foo = kmalloc(sizeof(*foo), GFP_KERNEL);
>
> This says you are allocating enough space for foo. It can be reviewed
> by looking at one line. If you change the type of foo it will still
> work.
>
> foo = kmalloc(sizeof(struct whatever), GFP_KERNEL);
>
> There isn't enough information to say if this is correct. If you change
> the type of foo then you have to update the allocation as well.
>
> It's not a super common type of bug, but I see it occasionally.

I know what you are saying, but the latter in my book is easier to read
and reminds you what the type is when you review the code.

Point being this comes down to personal preference and stating that the
former is the right way or making that a rule and using checkpatch to
harrass people with patches to change it is bogus.

Jes

2016-10-13 16:19:55

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 08:35:57 +0200

* Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
to make the corresponding size determination a bit safer according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 8d7df6d..d89958b 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
int rc = 0;
char *buffer;

- buffer = kzalloc(sizeof(char) * (RR3_FW_VERSION_LEN + 1), GFP_KERNEL);
+ buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
if (!buffer) {
dev_err(rr3->dev, "Memory allocation failure\n");
return;
@@ -741,7 +741,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
/* rr3 will disable rc detector on transmit */
rr3->transmitting = true;

- sample_lens = kzalloc(sizeof(int) * RR3_DRIVER_MAXLENS, GFP_KERNEL);
+ sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
+ sizeof(*sample_lens),
+ GFP_KERNEL);
if (!sample_lens) {
ret = -ENOMEM;
goto out;
--
2.10.1

2016-10-13 16:20:58

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 02/18] [media] RedRat3: Move two assignments in redrat3_transmit_ir()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:25:57 +0200

Move the assignment for the data structure member "transmitting"
and the local variable "curlencheck" behind the source code
for memory allocations by this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index d89958b..f5a6850 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -727,7 +727,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
int ret, ret_len;
int lencheck, cur_sample_len, pipe;
int *sample_lens = NULL;
- u8 curlencheck = 0;
+ u8 curlencheck;
unsigned i, sendbuf_len;

if (rr3->transmitting) {
@@ -738,9 +738,6 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
if (count > RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN)
return -EINVAL;

- /* rr3 will disable rc detector on transmit */
- rr3->transmitting = true;
-
sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
sizeof(*sample_lens),
GFP_KERNEL);
@@ -755,6 +752,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
goto out;
}

+ /* rr3 will disable rc detector on transmit */
+ rr3->transmitting = true;
+ curlencheck = 0;
for (i = 0; i < count; i++) {
cur_sample_len = redrat3_us_to_len(txbuf[i]);
if (cur_sample_len > 0xffff) {
--
2.10.1

2016-10-13 16:25:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 04/18] [media] RedRat3: One function call less in redrat3_transmit_ir() after error detection

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:50:24 +0200

The kfree() function was called in one case by the
redrat3_transmit_ir() function during error handling
even if the passed variable contained a null pointer.

* Adjust jump targets according to the Linux coding style convention.

* Move the resetting for the data structure member "transmitting"
at the end.

* Delete initialisations for the variables "irdata" and "sample_lens"
at the beginning which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 7ae2ced..71e901d 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
{
struct redrat3_dev *rr3 = rcdev->priv;
struct device *dev = rr3->dev;
- struct redrat3_irdata *irdata = NULL;
+ struct redrat3_irdata *irdata;
int ret, ret_len;
int lencheck, cur_sample_len, pipe;
- int *sample_lens = NULL;
+ int *sample_lens;
u8 curlencheck;
unsigned i, sendbuf_len;

@@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
if (!irdata) {
ret = -ENOMEM;
- goto out;
+ goto free_sample;
}

/* rr3 will disable rc detector on transmit */
@@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
curlencheck++;
} else {
ret = -EINVAL;
- goto out;
+ goto reset_member;
}
}
irdata->sigdata[i] = lencheck;
@@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
else
ret = count;
-
-out:
- kfree(irdata);
- kfree(sample_lens);
-
+reset_member:
rr3->transmitting = false;
/* rr3 re-enables rc detector because it was enabled before */
-
+ kfree(irdata);
+free_sample:
+ kfree(sample_lens);
return ret;
}

--
2.10.1

2016-10-13 16:27:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 05/18] [media] RedRat3: Delete six messages for a failed memory allocation

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:20:19 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: Possible unnecessary 'out of memory' message

Thus remove such a logging statement in five functions.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 71e901d..2e31c18 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -453,10 +453,8 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)

len = sizeof(*tmp);
tmp = kzalloc(len, GFP_KERNEL);
- if (!tmp) {
- dev_warn(rr3->dev, "Memory allocation faillure\n");
+ if (!tmp)
return timeout;
- }

pipe = usb_rcvctrlpipe(rr3->udev, 0);
ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM,
@@ -518,10 +516,8 @@ static void redrat3_reset(struct redrat3_dev *rr3)
txpipe = usb_sndctrlpipe(udev, 0);

val = kmalloc(len, GFP_KERNEL);
- if (!val) {
- dev_err(dev, "Memory allocation failure\n");
+ if (!val)
return;
- }

*val = 0x01;
rc = usb_control_msg(udev, rxpipe, RR3_RESET,
@@ -550,10 +546,8 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
char *buffer;

buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
- if (!buffer) {
- dev_err(rr3->dev, "Memory allocation failure\n");
+ if (!buffer)
return;
- }

rc = usb_control_msg(rr3->udev, usb_rcvctrlpipe(rr3->udev, 0),
RR3_FW_VERSION,
@@ -866,10 +860,8 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);

rc = rc_allocate_device();
- if (!rc) {
- dev_err(dev, "remote input dev allocation failed\n");
+ if (!rc)
goto out;
- }

snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
"Infrared Remote Transceiver (%04x:%04x)",
@@ -959,10 +951,8 @@ static int redrat3_dev_probe(struct usb_interface *intf,

/* allocate memory for our device state and initialize it */
rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL);
- if (rr3 == NULL) {
- dev_err(dev, "Memory allocation failure\n");
+ if (!rr3)
goto no_endpoints;
- }

rr3->dev = &intf->dev;

@@ -974,10 +964,8 @@ static int redrat3_dev_probe(struct usb_interface *intf,
rr3->ep_in = ep_in;
rr3->bulk_in_buf = usb_alloc_coherent(udev,
le16_to_cpu(ep_in->wMaxPacketSize), GFP_KERNEL, &rr3->dma_in);
- if (!rr3->bulk_in_buf) {
- dev_err(dev, "Read buffer allocation failure\n");
+ if (!rr3->bulk_in_buf)
goto error;
- }

pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress);
usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf,
--
2.10.1

2016-10-13 16:29:49

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 06/18] [media] RedRat3: Delete an unnecessary variable initialisation in redrat3_get_firmware_rev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:21:55 +0200

The local variable "rc" will be set to an appropriate value a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 2e31c18..0ac96a4 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -542,7 +542,7 @@ static void redrat3_reset(struct redrat3_dev *rr3)

static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
{
- int rc = 0;
+ int rc;
char *buffer;

buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
--
2.10.1

2016-10-13 16:32:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 03/18] [media] RedRat3: Return directly after a failed kcalloc() in redrat3_transmit_ir()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 10:34:29 +0200

* Return directly after a call of the function "kcalloc" failed
at the beginning.

* Reorder two calls for the function "kfree" at the end.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index f5a6850..7ae2ced 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -741,10 +741,8 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
sizeof(*sample_lens),
GFP_KERNEL);
- if (!sample_lens) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!sample_lens)
+ return -ENOMEM;

irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
if (!irdata) {
@@ -815,8 +813,8 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
ret = count;

out:
- kfree(sample_lens);
kfree(irdata);
+ kfree(sample_lens);

rr3->transmitting = false;
/* rr3 re-enables rc detector because it was enabled before */
--
2.10.1

2016-10-13 16:32:46

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 09/18] [media] RedRat3: Move a variable assignment in redrat3_dev_probe()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:07:03 +0200

* One local variable was set to an error code before a concrete
error situation was detected. Thus move the corresponding assignment
into three if branches to indicate a memory allocation failure there.

* Adjust a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index f6c21a1..f85117b 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -912,7 +912,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,
struct usb_endpoint_descriptor *ep_out = NULL;
u8 addr, attrs;
int pipe, i;
- int retval = -ENOMEM;
+ int retval;

uhi = intf->cur_altsetting;

@@ -951,21 +951,27 @@ static int redrat3_dev_probe(struct usb_interface *intf,

/* allocate memory for our device state and initialize it */
rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL);
- if (!rr3)
+ if (!rr3) {
+ retval = -ENOMEM;
goto no_endpoints;
+ }

rr3->dev = &intf->dev;

/* set up bulk-in endpoint */
rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!rr3->read_urb)
- goto error;
+ if (!rr3->read_urb) {
+ retval = -ENOMEM;
+ goto delete_rr;
+ }

rr3->ep_in = ep_in;
rr3->bulk_in_buf = usb_alloc_coherent(udev,
le16_to_cpu(ep_in->wMaxPacketSize), GFP_KERNEL, &rr3->dma_in);
- if (!rr3->bulk_in_buf)
- goto error;
+ if (!rr3->bulk_in_buf) {
+ retval = -ENOMEM;
+ goto delete_rr;
+ }

pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress);
usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf,
@@ -982,7 +988,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,
/* might be all we need to do? */
retval = redrat3_enable_detector(rr3);
if (retval < 0)
- goto error;
+ goto delete_rr;

/* store current hardware timeout, in µs */
rr3->hw_timeout = redrat3_get_timeout(rr3);
@@ -996,7 +1002,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,
rr3->led.brightness_set = redrat3_brightness_set;
retval = led_classdev_register(&intf->dev, &rr3->led);
if (retval)
- goto error;
+ goto delete_rr;

atomic_set(&rr3->flash, 0);
rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -1028,7 +1034,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,

led_free_error:
led_classdev_unregister(&rr3->led);
-error:
+delete_rr:
redrat3_delete(rr3, rr3->udev);

no_endpoints:
--
2.10.1

2016-10-13 16:33:10

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 07/18] [media] RedRat3: Improve another size determination in redrat3_reset()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:23:22 +0200

Replace the specification of a data type by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 0ac96a4..5832e6f 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -510,7 +510,7 @@ static void redrat3_reset(struct redrat3_dev *rr3)
struct device *dev = rr3->dev;
int rc, rxpipe, txpipe;
u8 *val;
- int len = sizeof(u8);
+ size_t const len = sizeof(*val);

rxpipe = usb_rcvctrlpipe(udev, 0);
txpipe = usb_sndctrlpipe(udev, 0);
--
2.10.1

2016-10-13 16:32:56

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 08/18] [media] RedRat3: Improve another size determination in redrat3_send_cmd()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 13:31:17 +0200

Replace the specification of a data type by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 5832e6f..f6c21a1 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -388,7 +388,7 @@ static int redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)
u8 *data;
int res;

- data = kzalloc(sizeof(u8), GFP_KERNEL);
+ data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

--
2.10.1

2016-10-13 16:33:20

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions

On Thu, 2016-10-13 at 18:18 +0200, SF Markus Elfring wrote:
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
[]
> @@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
> int rc = 0;
> char *buffer;
>
> - buffer = kzalloc(sizeof(char) * (RR3_FW_VERSION_LEN + 1), GFP_KERNEL);
> + buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
> if (!buffer) {
> dev_err(rr3->dev, "Memory allocation failure\n");
> return;,

Markus, please stop being _so_ mechanical and use your
brain a little too. By definition, sizeof(char) == 1.

This _really_ should be kzalloc(RR3_FW_VERSION_LEN + 1,...)

2016-10-13 16:36:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 10/18] [media] RedRat3: Delete an unnecessary variable initialisation in redrat3_init_rc_dev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:17:43 +0200

The local variable "ret" will be set to an appropriate value a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index f85117b..c43f43b 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -856,7 +856,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
{
struct device *dev = rr3->dev;
struct rc_dev *rc;
- int ret = -ENODEV;
+ int ret;
u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);

rc = rc_allocate_device();
--
2.10.1

2016-10-13 16:42:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:00:12 +0200

Adjust a jump label according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 74d93dd..055f214 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
ret = rc_register_device(rc);
if (ret < 0) {
dev_err(rr3->dev, "remote dev registration failed\n");
- goto out;
+ goto free_device;
}

return rc;
-
-out:
+free_device:
rc_free_device(rc);
return NULL;
}
--
2.10.1

2016-10-13 16:45:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 15/18] [media] RedRat3: Delete two variables in redrat3_set_timeout()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 15:40:33 +0200

* Use the data structure members "dev" and "udev" directly
without assigning them to intermediate variables.
Thus delete the extra variable definitions at the beginning.

* Fix indentation for the parameters of two function calls.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 055f214..e46a92a 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -476,8 +476,6 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)
static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)
{
struct redrat3_dev *rr3 = rc_dev->priv;
- struct usb_device *udev = rr3->udev;
- struct device *dev = rr3->dev;
__be32 *timeout;
int ret;

@@ -486,13 +484,17 @@ static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)
return -ENOMEM;

*timeout = cpu_to_be32(redrat3_us_to_len(timeoutns / 1000));
- ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), RR3_SET_IR_PARAM,
- USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
- RR3_IR_IO_SIG_TIMEOUT, 0, timeout, sizeof(*timeout),
- HZ * 25);
- dev_dbg(dev, "set ir parm timeout %d ret 0x%02x\n",
- be32_to_cpu(*timeout), ret);
-
+ ret = usb_control_msg(rr3->udev,
+ usb_sndctrlpipe(rr3->udev, 0),
+ RR3_SET_IR_PARAM,
+ USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
+ RR3_IR_IO_SIG_TIMEOUT,
+ 0,
+ timeout,
+ sizeof(*timeout),
+ HZ * 25);
+ dev_dbg(rr3->dev, "set ir parm timeout %d ret 0x%02x\n",
+ be32_to_cpu(*timeout), ret);
if (ret == sizeof(*timeout)) {
rr3->hw_timeout = timeoutns / 1000;
ret = 0;
--
2.10.1

2016-10-13 16:46:30

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 16/18] [media] RedRat3: Move a variable assignment in redrat3_set_timeout()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:13:41 +0200

Move the assignment for the local variable "rr3" behind the source code
for a memory allocation by this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index e46a92a..06c9eea 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -475,7 +475,7 @@ static u32 redrat3_get_timeout(struct redrat3_dev *rr3)

static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)
{
- struct redrat3_dev *rr3 = rc_dev->priv;
+ struct redrat3_dev *rr3;
__be32 *timeout;
int ret;

@@ -484,6 +484,7 @@ static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)
return -ENOMEM;

*timeout = cpu_to_be32(redrat3_us_to_len(timeoutns / 1000));
+ rr3 = rc_dev->priv;
ret = usb_control_msg(rr3->udev,
usb_sndctrlpipe(rr3->udev, 0),
RR3_SET_IR_PARAM,
--
2.10.1

2016-10-13 16:46:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 12/18] [media] RedRat3: Move a variable assignment in redrat3_init_rc_dev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:50:05 +0200

Move the assignment for the local variable "prod" behind the source code
for a memory allocation by this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index b23a8bb..002030f 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -856,12 +856,13 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
{
struct rc_dev *rc;
int ret;
- u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
+ u16 prod;

rc = rc_allocate_device();
if (!rc)
goto out;

+ prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
"Infrared Remote Transceiver (%04x:%04x)",
prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "",
--
2.10.1

2016-10-13 16:50:45

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 13/18] [media] RedRat3: Return directly after a failed rc_allocate_device() in redrat3_init_rc_dev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:54:46 +0200

Return directly after a call of the function "rc_allocate_device" failed
at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 002030f..74d93dd 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -860,7 +860,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)

rc = rc_allocate_device();
if (!rc)
- goto out;
+ return NULL;

prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
--
2.10.1

2016-10-13 16:55:12

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 18/18] [media] RedRat3: Combine substrings for six messages

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:50:11 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: quoted string split across lines

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index a09d5cb..b8c4b98 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -233,8 +233,7 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)

/* Codes 0x20 through 0x2f are IR Firmware Errors */
case 0x20:
- pr_cont("Initial signal pulse not long enough "
- "to measure carrier frequency\n");
+ pr_cont("Initial signal pulse not long enough to measure carrier frequency\n");
break;
case 0x21:
pr_cont("Not enough length values allocated for signal\n");
@@ -246,18 +245,15 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)
pr_cont("Too many signal repeats\n");
break;
case 0x28:
- pr_cont("Insufficient memory available for IR signal "
- "data memory allocation\n");
+ pr_cont("Insufficient memory available for IR signal data memory allocation\n");
break;
case 0x29:
- pr_cont("Insufficient memory available "
- "for IrDa signal data memory allocation\n");
+ pr_cont("Insufficient memory available for IrDa signal data memory allocation\n");
break;

/* Codes 0x30 through 0x3f are USB Firmware Errors */
case 0x30:
- pr_cont("Insufficient memory available for bulk "
- "transfer structure\n");
+ pr_cont("Insufficient memory available for bulk transfer structure\n");
break;

/*
@@ -269,8 +265,7 @@ static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)
pr_cont("Signal capture has been terminated\n");
break;
case 0x41:
- pr_cont("Attempt to set/get and unknown signal I/O "
- "algorithm parameter\n");
+ pr_cont("Attempt to set/get and unknown signal I/O algorithm parameter\n");
break;
case 0x42:
pr_cont("Signal capture already started\n");
@@ -866,8 +861,8 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
return NULL;

prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
- snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
- "Infrared Remote Transceiver (%04x:%04x)",
+ snprintf(rr3->name, sizeof(rr3->name),
+ "RedRat3%s Infrared Remote Transceiver (%04x:%04x)",
prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "",
le16_to_cpu(rr3->udev->descriptor.idVendor), prod);

--
2.10.1

2016-10-13 16:58:16

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 17/18] [media] RedRat3: Adjust two checks for null pointers in redrat3_dev_probe()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 17:40:34 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 06c9eea..a09d5cb 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -923,8 +923,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,
ep = &uhi->endpoint[i].desc;
addr = ep->bEndpointAddress;
attrs = ep->bmAttributes;
-
- if ((ep_in == NULL) &&
+ if (!ep_in &&
((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
USB_ENDPOINT_XFER_BULK)) {
@@ -935,7 +934,7 @@ static int redrat3_dev_probe(struct usb_interface *intf,
ep_in = ep;
}

- if ((ep_out == NULL) &&
+ if (!ep_out &&
((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
USB_ENDPOINT_XFER_BULK)) {
--
2.10.1

2016-10-13 17:16:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 00/18] [media] RedRat3: Fine-tuning for several function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 18:06:18 +0200

Several update suggestions were taken into account
from static source code analysis.

Markus Elfring (18):
Use kcalloc() in two functions
Move two assignments in redrat3_transmit_ir()
Return directly after a failed kcalloc() in redrat3_transmit_ir()
One function call less in redrat3_transmit_ir() after error detection
Delete six messages for a failed memory allocation
Delete an unnecessary variable initialisation in redrat3_get_firmware_rev()
Improve another size determination in redrat3_reset()
Improve another size determination in redrat3_send_cmd()
Move a variable assignment in redrat3_dev_probe()
Delete an unnecessary variable initialisation in redrat3_init_rc_dev()
Delete the variable "dev" in redrat3_init_rc_dev()
Move a variable assignment in redrat3_init_rc_dev()
Return directly after a failed rc_allocate_device() in redrat3_init_rc_dev()
Rename a jump label in redrat3_init_rc_dev()
Delete two variables in redrat3_set_timeout()
Move a variable assignment in redrat3_set_timeout()
Adjust two checks for null pointers in redrat3_dev_probe()
Combine substrings for six messages

drivers/media/rc/redrat3.c | 146 +++++++++++++++++++++------------------------
1 file changed, 67 insertions(+), 79 deletions(-)

--
2.10.1

2016-10-13 17:27:11

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 11/18] [media] RedRat3: Delete the variable "dev" in redrat3_init_rc_dev()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Oct 2016 14:40:11 +0200

Use the data structure member "dev" directly without assigning it
to an intermediate variable.
Thus delete the extra variable definition at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/redrat3.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index c43f43b..b23a8bb 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -854,7 +854,6 @@ static void redrat3_led_complete(struct urb *urb)

static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
{
- struct device *dev = rr3->dev;
struct rc_dev *rc;
int ret;
u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
@@ -873,7 +872,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
rc->input_name = rr3->name;
rc->input_phys = rr3->phys;
usb_to_input_id(rr3->udev, &rc->input_id);
- rc->dev.parent = dev;
+ rc->dev.parent = rr3->dev;
rc->priv = rr3;
rc->driver_type = RC_DRIVER_IR_RAW;
rc->allowed_protocols = RC_BIT_ALL;
@@ -889,7 +888,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)

ret = rc_register_device(rc);
if (ret < 0) {
- dev_err(dev, "remote dev registration failed\n");
+ dev_err(rr3->dev, "remote dev registration failed\n");
goto out;
}

--
2.10.1

2016-10-13 21:39:08

by Sean Young

[permalink] [raw]
Subject: Re: [PATCH 12/18] [media] RedRat3: Move a variable assignment in redrat3_init_rc_dev()

On Thu, Oct 13, 2016 at 06:39:23PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 13 Oct 2016 14:50:05 +0200
>
> Move the assignment for the local variable "prod" behind the source code
> for a memory allocation by this function.

The redrat3 driver shouldn't be adding the usb vendor/product id to the
device name. A better patch would be to remove those from the snprintf
completely and to away with the local variable.

Sean

>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/redrat3.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
> index b23a8bb..002030f 100644
> --- a/drivers/media/rc/redrat3.c
> +++ b/drivers/media/rc/redrat3.c
> @@ -856,12 +856,13 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
> {
> struct rc_dev *rc;
> int ret;
> - u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
> + u16 prod;
>
> rc = rc_allocate_device();
> if (!rc)
> goto out;
>
> + prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
> snprintf(rr3->name, sizeof(rr3->name), "RedRat3%s "
> "Infrared Remote Transceiver (%04x:%04x)",
> prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "",
> --
> 2.10.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2016-10-14 05:47:13

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] RedRat3: Use kcalloc() in two functions?

> Markus, please stop being _so_ mechanical and use your
> brain a little too. By definition, sizeof(char) == 1.
>
> This _really_ should be kzalloc(RR3_FW_VERSION_LEN + 1,...)

Do you expect that function call examples like the following will be equivalent?

zbuffer = kzalloc(123, ?);
cbuffer = kcalloc(123, 1, ?);

Regards,
Markus

2016-10-14 08:19:13

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 02/18] [media] RedRat3: Move two assignments in redrat3_transmit_ir()

I have asked you about six or seven times to only send bug fixes and
stop sending clean up patches. You have refused. But now I'm asking
you to stop randomly doing things without at least thinking about it for
a bit.

The original code was correct.

regards,
dan carpenter

2016-10-14 11:40:34

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/5] [media] winbond-cir: Fine-tuning for four function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 13:24:35 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Use kmalloc_array() in wbcir_tx()
Move a variable assignment in wbcir_tx()
Move assignments for three variables in wbcir_shutdown()
One variable and its check less in wbcir_shutdown() after error detection
Move a variable assignment in two functions

drivers/media/rc/winbond-cir.c | 95 +++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 51 deletions(-)

--
2.10.1

2016-10-14 11:43:29

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 10:40:12 +0200

Move the setting for the local variables "mask", "match" and "rc6_csl"
behind the source code for a condition check by this function
at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/winbond-cir.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index fd997f0..9d05e17 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)
bool do_wake = true;
u8 match[11];
u8 mask[11];
- u8 rc6_csl = 0;
+ u8 rc6_csl;
int i;

- memset(match, 0, sizeof(match));
- memset(mask, 0, sizeof(mask));
-
if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
do_wake = false;
goto finish;
}

+ rc6_csl = 0;
+ memset(match, 0, sizeof(match));
+ memset(mask, 0, sizeof(mask));
switch (protocol) {
case IR_PROTOCOL_RC5:
if (wake_sc > 0xFFF) {
--
2.10.1

2016-10-14 11:44:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 12:48:41 +0200

The local variable "do_wake" was set to "false" after an invalid system
setting was detected so that a bit of error handling was triggered.

* Replace these assignments by direct jumps to the source code with the
desired exception handling.

* Delete this status variable and a corresponding check which became
unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 44 deletions(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 9d05e17..3d286b9 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
{
struct device *dev = &device->dev;
struct wbcir_data *data = pnp_get_drvdata(device);
- bool do_wake = true;
u8 match[11];
u8 mask[11];
u8 rc6_csl;
int i;

- if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
- do_wake = false;
- goto finish;
- }
+ if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
+ goto clear_bits;

rc6_csl = 0;
memset(match, 0, sizeof(match));
@@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
switch (protocol) {
case IR_PROTOCOL_RC5:
if (wake_sc > 0xFFF) {
- do_wake = false;
dev_err(dev, "RC5 - Invalid wake scancode\n");
- break;
+ goto clear_bits;
}

/* Mask = 13 bits, ex toggle */
@@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)

case IR_PROTOCOL_NEC:
if (wake_sc > 0xFFFFFF) {
- do_wake = false;
dev_err(dev, "NEC - Invalid wake scancode\n");
- break;
+ goto clear_bits;
}

mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
@@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)

if (wake_rc6mode == 0) {
if (wake_sc > 0xFFFF) {
- do_wake = false;
dev_err(dev, "RC6 - Invalid wake scancode\n");
- break;
+ goto clear_bits;
}

/* Command */
@@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
} else if (wake_sc <= 0x007FFFFF) {
rc6_csl = 60;
} else {
- do_wake = false;
dev_err(dev, "RC6 - Invalid wake scancode\n");
- break;
+ goto clear_bits;
}

/* Header */
@@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
mask[i++] = 0x0F;

} else {
- do_wake = false;
dev_err(dev, "RC6 - Invalid wake mode\n");
+ goto clear_bits;
}

break;

default:
- do_wake = false;
- break;
+ goto clear_bits;
}

-finish:
- if (do_wake) {
- /* Set compare and compare mask */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
- WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
- 0x3F);
- outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
- WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
- 0x3F);
- outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
-
- /* RC6 Compare String Len */
- outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
-
- /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
+ /* Set compare and compare mask */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
+ WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
+ 0x3F);
+ outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
+ WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
+ 0x3F);
+ outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);

- /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
+ /* RC6 Compare String Len */
+ outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);

- /* Set CEIR_EN */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
-
- } else {
- /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
+ /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);

- /* Clear CEIR_EN */
- wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
- }
+ /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);

+ /* Set CEIR_EN */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
+set_irqmask:
/*
* ACPI will set the HW disable bit for SP3 which means that the
* output signals are left in an undefined state which may cause
@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
*/
wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
disable_irq(data->irq);
+ return;
+clear_bits:
+ /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
+
+ /* Clear CEIR_EN */
+ wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
+ goto set_irqmask;
}

static int
--
2.10.1

2016-10-14 11:45:06

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:34:46 +0200

Move the assignment for the local variable "data" behind the source code
for a memory allocation by this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/winbond-cir.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 59050f5..fd997f0 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
static int
wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
{
- struct wbcir_data *data = dev->priv;
+ struct wbcir_data *data;
unsigned *buf;
unsigned i;
unsigned long flags;
@@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
for (i = 0; i < count; i++)
buf[i] = DIV_ROUND_CLOSEST(b[i], 10);

+ data = dev->priv;
/* Not sure if this is possible, but better safe than sorry */
spin_lock_irqsave(&data->spinlock, flags);
if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
--
2.10.1

2016-10-14 11:45:17

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 07:19:00 +0200

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/winbond-cir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 95ae60e..59050f5 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
unsigned i;
unsigned long flags;

- buf = kmalloc(count * sizeof(*b), GFP_KERNEL);
+ buf = kmalloc_array(count, sizeof(*b), GFP_KERNEL);
if (!buf)
return -ENOMEM;

--
2.10.1

2016-10-14 11:45:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions

From: Markus Elfring <[email protected]>
Date: Fri, 14 Oct 2016 13:13:11 +0200

Move the assignment for the local variable "data" behind the source code
for condition checks by these functions.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/rc/winbond-cir.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 3d286b9..716b1fe 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)
static int
wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
{
- struct wbcir_data *data = dev->priv;
+ struct wbcir_data *data;
unsigned long flags;
u8 val;
u32 freq;
@@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
break;
}

+ data = dev->priv;
spin_lock_irqsave(&data->spinlock, flags);
if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
spin_unlock_irqrestore(&data->spinlock, flags);
@@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
static int
wbcir_txmask(struct rc_dev *dev, u32 mask)
{
- struct wbcir_data *data = dev->priv;
+ struct wbcir_data *data;
unsigned long flags;
u8 val;

@@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
return -EINVAL;
}

+ data = dev->priv;
spin_lock_irqsave(&data->spinlock, flags);
if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
spin_unlock_irqrestore(&data->spinlock, flags);
--
2.10.1

2016-10-14 12:02:14

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] RedRat3: Move two assignments in redrat3_transmit_ir()?

> The original code was correct.

Your view can be appropriate for this function implementation to some degree.

I got the impression that it contains the specification of assignments
which will happen a bit too early here.
Is this a weakness for which software developers can care about?

Regards,
Markus

2016-10-15 13:30:56

by Sean Young

[permalink] [raw]
Subject: Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

On Fri, Oct 14, 2016 at 01:44:02PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 14 Oct 2016 12:48:41 +0200
>
> The local variable "do_wake" was set to "false" after an invalid system
> setting was detected so that a bit of error handling was triggered.
>
> * Replace these assignments by direct jumps to the source code with the
> desired exception handling.
>
> * Delete this status variable and a corresponding check which became
> unnecessary with this refactoring.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
> 1 file changed, 34 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 9d05e17..3d286b9 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
> {
> struct device *dev = &device->dev;
> struct wbcir_data *data = pnp_get_drvdata(device);
> - bool do_wake = true;
> u8 match[11];
> u8 mask[11];
> u8 rc6_csl;
> int i;
>
> - if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
> - do_wake = false;
> - goto finish;
> - }
> + if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
> + goto clear_bits;
>
> rc6_csl = 0;
> memset(match, 0, sizeof(match));
> @@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
> switch (protocol) {
> case IR_PROTOCOL_RC5:
> if (wake_sc > 0xFFF) {
> - do_wake = false;
> dev_err(dev, "RC5 - Invalid wake scancode\n");
> - break;
> + goto clear_bits;
> }
>
> /* Mask = 13 bits, ex toggle */
> @@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)
>
> case IR_PROTOCOL_NEC:
> if (wake_sc > 0xFFFFFF) {
> - do_wake = false;
> dev_err(dev, "NEC - Invalid wake scancode\n");
> - break;
> + goto clear_bits;
> }
>
> mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
> @@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)
>
> if (wake_rc6mode == 0) {
> if (wake_sc > 0xFFFF) {
> - do_wake = false;
> dev_err(dev, "RC6 - Invalid wake scancode\n");
> - break;
> + goto clear_bits;
> }
>
> /* Command */
> @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
> } else if (wake_sc <= 0x007FFFFF) {
> rc6_csl = 60;
> } else {
> - do_wake = false;
> dev_err(dev, "RC6 - Invalid wake scancode\n");
> - break;
> + goto clear_bits;
> }
>
> /* Header */
> @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
> mask[i++] = 0x0F;
>
> } else {
> - do_wake = false;
> dev_err(dev, "RC6 - Invalid wake mode\n");
> + goto clear_bits;
> }
>
> break;
>
> default:
> - do_wake = false;
> - break;
> + goto clear_bits;
> }
>
> -finish:
> - if (do_wake) {
> - /* Set compare and compare mask */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> - WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
> - 0x3F);
> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> - WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
> - 0x3F);
> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
> -
> - /* RC6 Compare String Len */
> - outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
> -
> - /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
> + /* Set compare and compare mask */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> + WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
> + 0x3F);
> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> + WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
> + 0x3F);
> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>
> - /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
> + /* RC6 Compare String Len */
> + outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>
> - /* Set CEIR_EN */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
> -
> - } else {
> - /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
> + /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>
> - /* Clear CEIR_EN */
> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
> - }
> + /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>
> + /* Set CEIR_EN */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
> +set_irqmask:
> /*
> * ACPI will set the HW disable bit for SP3 which means that the
> * output signals are left in an undefined state which may cause
> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
> */
> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
> disable_irq(data->irq);
> + return;
> +clear_bits:
> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
> +
> + /* Clear CEIR_EN */
> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
> + goto set_irqmask;

I'm not convinced that adding a goto which goes backwards is making this
code any more readible, just so that a local variable can be dropped.


Sean

> }
>
> static int
> --
> 2.10.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2016-10-15 13:43:37

by Sean Young

[permalink] [raw]
Subject: Re: [PATCH 04/18] [media] RedRat3: One function call less in redrat3_transmit_ir() after error detection

On Thu, Oct 13, 2016 at 06:24:46PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Thu, 13 Oct 2016 10:50:24 +0200
>
> The kfree() function was called in one case by the
> redrat3_transmit_ir() function during error handling
> even if the passed variable contained a null pointer.
>
> * Adjust jump targets according to the Linux coding style convention.
>
> * Move the resetting for the data structure member "transmitting"
> at the end.
>
> * Delete initialisations for the variables "irdata" and "sample_lens"
> at the beginning which became unnecessary with this refactoring.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/redrat3.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
> index 7ae2ced..71e901d 100644
> --- a/drivers/media/rc/redrat3.c
> +++ b/drivers/media/rc/redrat3.c
> @@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
> {
> struct redrat3_dev *rr3 = rcdev->priv;
> struct device *dev = rr3->dev;
> - struct redrat3_irdata *irdata = NULL;
> + struct redrat3_irdata *irdata;
> int ret, ret_len;
> int lencheck, cur_sample_len, pipe;
> - int *sample_lens = NULL;
> + int *sample_lens;
> u8 curlencheck;
> unsigned i, sendbuf_len;
>
> @@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
> irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
> if (!irdata) {
> ret = -ENOMEM;
> - goto out;
> + goto free_sample;
> }
>
> /* rr3 will disable rc detector on transmit */
> @@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
> curlencheck++;
> } else {
> ret = -EINVAL;
> - goto out;
> + goto reset_member;
> }
> }
> irdata->sigdata[i] = lencheck;
> @@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
> dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
> else
> ret = count;
> -
> -out:
> - kfree(irdata);
> - kfree(sample_lens);
> -
> +reset_member:
> rr3->transmitting = false;
> /* rr3 re-enables rc detector because it was enabled before */
> -
> + kfree(irdata);
> +free_sample:
> + kfree(sample_lens);

In this error path, rr3->transmitting is not set to false so now the driver
will never allow you transmit again.

Also this patch does not apply against latest.

Sean

> return ret;
> }
>
> --
> 2.10.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2016-10-15 16:43:10

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

>> + /* Set CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> +set_irqmask:
>> /*
>> * ACPI will set the HW disable bit for SP3 which means that the
>> * output signals are left in an undefined state which may cause
>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>> */
>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>> disable_irq(data->irq);
>> + return;
>> +clear_bits:
>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> +
>> + /* Clear CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> + goto set_irqmask;
>
> I'm not convinced that adding a goto which goes backwards is making this
> code any more readible, just so that a local variable can be dropped.

Thanks for your feedback.

Is such a "backward jump" usual and finally required when you would like
to move a bit of common error handling code to the end without using extra
local variables and a few statements should still be performed after it?

Regards,
Markus

2016-10-15 17:00:37

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 04/18] [media] RedRat3: One function call less in redrat3_transmit_ir() after error detection

>> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
>> index 7ae2ced..71e901d 100644
>> --- a/drivers/media/rc/redrat3.c
>> +++ b/drivers/media/rc/redrat3.c
>> @@ -723,10 +723,10 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
>> {
>> struct redrat3_dev *rr3 = rcdev->priv;
>> struct device *dev = rr3->dev;
>> - struct redrat3_irdata *irdata = NULL;
>> + struct redrat3_irdata *irdata;
>> int ret, ret_len;
>> int lencheck, cur_sample_len, pipe;
>> - int *sample_lens = NULL;
>> + int *sample_lens;
>> u8 curlencheck;
>> unsigned i, sendbuf_len;
>>
>> @@ -747,7 +747,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
>> irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
>> if (!irdata) {
>> ret = -ENOMEM;
>> - goto out;
>> + goto free_sample;
>> }
>>
>> /* rr3 will disable rc detector on transmit */
>> @@ -776,7 +776,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
>> curlencheck++;
>> } else {
>> ret = -EINVAL;
>> - goto out;
>> + goto reset_member;
>> }
>> }
>> irdata->sigdata[i] = lencheck;
>> @@ -811,14 +811,12 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
>> dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
>> else
>> ret = count;
>> -
>> -out:
>> - kfree(irdata);
>> - kfree(sample_lens);
>> -
>> +reset_member:
>> rr3->transmitting = false;
>> /* rr3 re-enables rc detector because it was enabled before */
>> -
>> + kfree(irdata);
>> +free_sample:
>> + kfree(sample_lens);
>
> In this error path, rr3->transmitting is not set to false

Can it be that this reset is not needed because it should have still got this value already
in the software refactoring I proposed here?


> so now the driver will never allow you transmit again.

I have got an other impression.


> Also this patch does not apply against latest.

Do you want that I rebase my update suggestion for this software module on a published commit
that is more recent than 2016-09-22 (d6ae162bd13998a6511e5efbc7c19ab542ba1555 for example)?

Regards,
Markus

2016-10-16 08:20:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH] MD-RAID: Use seq_putc() in three status functions

From: Markus Elfring <[email protected]>
Date: Sun, 16 Oct 2016 10:10:28 +0200

A single character (a closing square bracket) should be put into a sequence
at the end in these functions.
Thus use the corresponding function "seq_putc".

This issue was detected also by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 2 +-
drivers/md/raid5.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 1961d82..fd97f65 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1418,7 +1418,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev)
rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf(seq, "]");
+ seq_putc(seq, ']');
}

static void raid1_error(struct mddev *mddev, struct md_rdev *rdev)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index be1a9fc..7490b28 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1499,7 +1499,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)
seq_printf(seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf(seq, "]");
+ seq_putc(seq, ']');
}

/* check if there are enough drives for
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 92ac251..9eb45c4 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7077,7 +7077,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf (seq, "]");
+ seq_putc(seq, ']');
}

static void print_raid5_conf (struct r5conf *conf)
--
2.10.1

2016-10-16 16:58:30

by Hannes Reinecke

[permalink] [raw]
Subject: Re: [PATCH] MD-RAID: Use seq_putc() in three status functions

On 10/16/2016 10:20 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sun, 16 Oct 2016 10:10:28 +0200
>
> A single character (a closing square bracket) should be put into a sequence
> at the end in these functions.
> Thus use the corresponding function "seq_putc".
>
> This issue was detected also by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/md/raid1.c | 2 +-
> drivers/md/raid10.c | 2 +-
> drivers/md/raid5.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 1961d82..fd97f65 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1418,7 +1418,7 @@ static void raid1_status(struct seq_file *seq, struct mddev *mddev)
> rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> }
> rcu_read_unlock();
> - seq_printf(seq, "]");
> + seq_putc(seq, ']');
> }
>
> static void raid1_error(struct mddev *mddev, struct md_rdev *rdev)
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index be1a9fc..7490b28 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -1499,7 +1499,7 @@ static void raid10_status(struct seq_file *seq, struct mddev *mddev)
> seq_printf(seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> }
> rcu_read_unlock();
> - seq_printf(seq, "]");
> + seq_putc(seq, ']');
> }
>
> /* check if there are enough drives for
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 92ac251..9eb45c4 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -7077,7 +7077,7 @@ static void raid5_status(struct seq_file *seq, struct mddev *mddev)
> seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> }
> rcu_read_unlock();
> - seq_printf (seq, "]");
> + seq_putc(seq, ']');
> }
>
> static void print_raid5_conf (struct r5conf *conf)
>
The point of this patch being ... what?
Does it improve code? Does it improve anything?

Cheers,

Hannes
--
Dr. Hannes Reinecke zSeries & Storage
[email protected] +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: J. Hawn, J. Guild, F. Imend?rffer, HRB 16746 (AG N?rnberg)

2016-10-16 17:11:05

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

> Does it improve code? Does it improve anything?

Yes. - I got such an impression.

* Is it more efficient to call the function "seq_printf" for the desired data processing
for a single character than to pass it to the function "" in a string?

* Will the required data transfer shrink a bit for the affected functions because of
such a change?

Regards,
Markus

2016-10-16 17:18:52

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

> Yes. - I got such an impression.

Correction:

* Is it more efficient to call the function "seq_putc" for the desired data processing
for a single character than to pass it to the function "seq_printf" in a string?

* Will the required data transfer shrink a bit for the affected functions because of
such a change?
How do you think about to reduce the transmission for such tiny strings
containing delimiters?

Regards,
Markus

2016-10-17 05:58:59

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/16/2016 07:10 PM, SF Markus Elfring wrote:
>> Does it improve code? Does it improve anything?
>
> Yes. - I got such an impression.
>
> * Is it more efficient to call the function "seq_printf" for the desired data processing
> for a single character than to pass it to the function "" in a string?
>
> * Will the required data transfer shrink a bit for the affected functions because of
> such a change?
>
Which are questions _you_ should be able to answer.
It's your patch, after all.
Once you do (and prove that the answer is 'yes' to the above two
questions) the patch will be applied.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

2016-10-17 07:40:13

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>>> Does it improve code? Does it improve anything?
>>
>> Yes. - I got such an impression.
>>
>> * Is it more efficient to call the function "seq_printf" for the desired data processing
>> for a single character than to pass it to the function "" in a string?
>>
>> * Will the required data transfer shrink a bit for the affected functions because of
>> such a change?
>>
> Which are questions _you_ should be able to answer.

I wonder that the answers are not obvious for you already.

Calling the function "seq_putc" will be more efficient than "seq_printf"
in this case because of the following reasons.

1. How does the distribution look like for supported processor architectures
where the data transfer for bytes (as a function call parameter)
is faster than for (string) pointers?

2. Did anybody measure already how many the execution times can vary
for these functions?

3. seq_printf() provides more functionality as this kind of programming
interface was designed for a bigger purpose.
How much do you care for consequences when such general functions
are called with input data they were not designed for mainly?

4. The seq_putc() implementation is so simple.
http://lxr.free-electrons.com/source/fs/seq_file.c?v=4.8#L657

Where do you get doubts about its efficiency for the data processing
of a single character?


> It's your patch, after all.

Yes. - I published a special update suggestion once again.


> Once you do (and prove that the answer is 'yes' to the above two
> questions) the patch will be applied.

How do you think about to share a bit more from your software development
and testing experience?
Which call frequencies do you observe for the affected functions?

1. raid1_status
2. raid10_status
3. raid5_status

Regards,
Markus

2016-10-17 08:12:23

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 09:39 AM, SF Markus Elfring wrote:
>>>> Does it improve code? Does it improve anything?
>>>
>>> Yes. - I got such an impression.
>>>
>>> * Is it more efficient to call the function "seq_printf" for the desired data processing
>>> for a single character than to pass it to the function "" in a string?
>>>
>>> * Will the required data transfer shrink a bit for the affected functions because of
>>> such a change?
>>>
>> Which are questions _you_ should be able to answer.
>
> I wonder that the answers are not obvious for you already.
>
> Calling the function "seq_putc" will be more efficient than "seq_printf"
> in this case because of the following reasons.
>
> 1. How does the distribution look like for supported processor architectures
> where the data transfer for bytes (as a function call parameter)
> is faster than for (string) pointers?
>
How would I know? I would assume that _you_ did some measurements here;
after all, _you_ are trying to push this patch.
I could easily claim that seq_printf() is more efficient than
seq_putc(), and won't apply your patch.
So _you_ have to prove that your patch is more efficient.

> 2. Did anybody measure already how many the execution times can vary
> for these functions?
>
Probably not.
But referring to the previous topic:
Unless _you_ prove that _your_ patch is more efficient it won't get
applied. _You_ want us to apply your patch, so the burden is on _you_ to
provide the required data.


> Where do you get doubts about its efficiency for the data processing
> of a single character?
>
Because it's being called at the end of a function calling seq_printf()
already. So exchanging a single call is probably not helping anything,
as the compiler will optimize it anyway.
Case in point: with your patch the x86_64 compiler generates nearly
identical code for driver/md/raid1.c, but with one instruction _more_
after your patch has been applied.

So it's not immediately obvious that your patch is an improvement.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)

2016-10-17 09:01:31

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>> Calling the function "seq_putc" will be more efficient than "seq_printf"
>> in this case because of the following reasons.
>>
>> 1. How does the distribution look like for supported processor architectures
>> where the data transfer for bytes (as a function call parameter)
>> is faster than for (string) pointers?
>>
> How would I know?

How many processor architecture characteristics do you know already?

* Is a string pointer often longer than a byte?

* I imagine that it can become also interesting to check byte level data access
under constraints of machine word sizes and alignment.


> I would assume that _you_ did some measurements here;

How much would you trust in any concrete numbers I could present
for this use case?

Do you give more trust to a reference testing platform?


> I could easily claim that seq_printf() is more efficient than
> seq_putc(), and won't apply your patch.

This is also possible in principle.


> So _you_ have to prove that your patch is more efficient.

How many results would we like to clarify from various hardware
and software combinations?


>> 2. Did anybody measure already how many the execution times can vary
>> for these functions?
>>
> Probably not.

Thanks for this information.

How important are the mentioned functions for you within the Linux
programming interface so far?


> Unless _you_ prove that _your_ patch is more efficient it won't get applied.

Which data would you accept as a "prove" in this case?


>> Where do you get doubts about its efficiency for the data processing
>> of a single character?
>>
> Because it's being called at the end of a function calling seq_printf() already.

Interesting view ?


> So exchanging a single call is probably not helping anything,
> as the compiler will optimize it anyway.

How common is the discussed software transformation between implementations
for optimising compilers?


> Case in point: with your patch the x86_64 compiler generates nearly
> identical code for driver/md/raid1.c, but with one instruction _more_
> after your patch has been applied.

Which software versions and command parameters did you try out
for this information (from an unspecified run time environment)?


> So it's not immediately obvious that your patch is an improvement.

I agree that there are system properties and constraints which can be
considered further.

Regards,
Markus

2016-10-17 09:51:23

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 11:00 AM, SF Markus Elfring wrote:
>>> Calling the function "seq_putc" will be more efficient than "seq_printf"
>>> in this case because of the following reasons.
>>>
>>> 1. How does the distribution look like for supported processor architectures
>>> where the data transfer for bytes (as a function call parameter)
>>> is faster than for (string) pointers?
>>>
>> How would I know?
>
> How many processor architecture characteristics do you know already?
>
x86, s390x, ppc/ppc64.

> * Is a string pointer often longer than a byte?
>
Always.

(Which up to now I thought was basic programming knowledge...)

> * I imagine that it can become also interesting to check byte level data access
> under constraints of machine word sizes and alignment.
>
So, another test for you to do.

>
>> I would assume that _you_ did some measurements here;
>
> How much would you trust in any concrete numbers I could present
> for this use case?
>
> Do you give more trust to a reference testing platform?
>
At the moment _any_ test would do.
With every response from your side you just keep on asking further
questions. But so far you haven't delivered any answers nor measurements.

>
>> I could easily claim that seq_printf() is more efficient than
>> seq_putc(), and won't apply your patch.
>
> This is also possible in principle.
>
No, this is what's going to happen if you don't show any measurements.

>
>> So _you_ have to prove that your patch is more efficient.
>
> How many results would we like to clarify from various hardware
> and software combinations?
>
See above. At the moment _any_ test result from your side would do.

>
>>> 2. Did anybody measure already how many the execution times can vary
>>> for these functions?
>>>
>> Probably not.
>
> Thanks for this information.
>
> How important are the mentioned functions for you within the Linux
> programming interface so far?
>
Not very. The interface is only used in a slow path, and the execution
time doesn't affect I/O performance in any way.

>
>> Unless _you_ prove that _your_ patch is more efficient it won't get applied.
>
> Which data would you accept as a "prove" in this case?
>
Again: You want something from us. We don't have to prove anything, you
need to convince us. And it is really hard to convince anyone by asking
questions.

>
>>> Where do you get doubts about its efficiency for the data processing
>>> of a single character?
>>>
>> Because it's being called at the end of a function calling seq_printf() already.
>
> Interesting view ?
>
>
>> So exchanging a single call is probably not helping anything,
>> as the compiler will optimize it anyway.
>
> How common is the discussed software transformation between implementations
> for optimising compilers?
>
>
>> Case in point: with your patch the x86_64 compiler generates nearly
>> identical code for driver/md/raid1.c, but with one instruction _more_
>> after your patch has been applied.
>
> Which software versions and command parameters did you try out
> for this information (from an unspecified run time environment)?
>
>
# gcc --version
gcc (SUSE Linux) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

git tree from git.kernel.org/mkp/u/4.10/scsi-queue

_I_ did some measurements.
I'm still waiting from results from your side.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)

2016-10-17 11:15:58

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>> * Is a string pointer often longer than a byte?
>>
> Always.

I have got doubts for this specific information.


> (Which up to now I thought was basic programming knowledge...)

By the way:
Run time environments still exist where the size of a pointer can be also
just one byte, don't they?


>> How many results would we like to clarify from various hardware
>> and software combinations?
>>
> See above. At the moment _any_ test result from your side would do.

I imagine that another single result might not be representative.
How many lessons from test statistics will usually be also relevant here?


>> How important are the mentioned functions for you within the Linux
>> programming interface so far?
>>
> Not very. The interface is only used in a slow path, and the execution
> time doesn't affect I/O performance in any way.

Thanks for another interesting information.


>>> Case in point: with your patch the x86_64 compiler generates nearly
>>> identical code for driver/md/raid1.c, but with one instruction _more_
>>> after your patch has been applied.
>>
>> Which software versions and command parameters did you try out
>> for this information (from an unspecified run time environment)?
>>
> # gcc --version
> gcc (SUSE Linux) 4.8.5

Thanks for this detail.

* Did you choose any special optimisation settings for your quick check?

* Will any compilation results matter if "optimisation" would be
switched off there?


> I'm still waiting from results from your side.

Would any other software developers or testers dare to add related information?

Regards,
Markus

2016-10-17 11:44:48

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>>> See above. At the moment _any_ test result from your side would do.
>>
>> I imagine that another single result might not be representative.
>
> Publish not only results but also everything (complete!) so that anyone
> can *easily* follow it to check and reproduce the results - especially
> if you want people with knowledge of other architectures to comment
> (otherwise they probably won't bother).

Am I the only software developer so far who would dare to reconsider
implementation details from three status functions?

Regards,
Markus

2016-10-17 12:10:24

by Bernd Petrovitsch

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On Mon, 2016-10-17 at 13:10 +0200, SF Markus Elfring wrote:
[...]
> > (Which up to now I thought was basic programming knowledge...)
>
> By the way:
> Run time environments still exist where the size of a pointer can
> be also just one byte, don't they?

In the context of the Linux kernel: No.

[ Side note: there might be some DSP out there with a running Linux
kernel which cannot really address a "byte" (meaning 8bits) but only in
register sized quantities (and also aligned for that). But no one cares
here really deeply as that is a so fundamental difference that the C-
compiler must cope with that anyways in the first place. ]

[...]
> > See above. At the moment _any_ test result from your side would do.
>
> I imagine that another single result might not be representative.

Publish not only results but also everything (complete!) so that anyone
can *easily* follow it to check and reproduce the results - especially
if you want people with knowledge of other architectures to comment
(otherwise they probably won't bother).

Kind regards,
Bernd
--
Bernd Petrovitsch Email : [email protected]
LUGA : http://www.luga.at

2016-10-17 14:02:02

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 01:43 PM, SF Markus Elfring wrote:
>>>> See above. At the moment _any_ test result from your side would do.
>>>
>>> I imagine that another single result might not be representative.
>>
>> Publish not only results but also everything (complete!) so that anyone
>> can *easily* follow it to check and reproduce the results - especially
>> if you want people with knowledge of other architectures to comment
>> (otherwise they probably won't bother).
>
> Am I the only software developer so far who would dare to reconsider
> implementation details from three status functions?
>
No.
But we're waiting for you showing is that it is an improvement.
Which at the moment we don't see.
Hence we're waiting from a proof or validation from your side.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)

2016-10-17 14:03:11

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 01:10 PM, SF Markus Elfring wrote:
>>> * Is a string pointer often longer than a byte?
>>>
>> Always.
>
> I have got doubts for this specific information.
>
>
>> (Which up to now I thought was basic programming knowledge...)
>
> By the way:
> Run time environments still exist where the size of a pointer can be also
> just one byte, don't they?
>
Really? Name one.
You can only fit a point in one byte if you are on an 8-bit system.
Which I don't think linux is running on.

>>> How many results would we like to clarify from various hardware
>>> and software combinations?
>>>
>> See above. At the moment _any_ test result from your side would do.
>
> I imagine that another single result might not be representative.
> How many lessons from test statistics will usually be also relevant here?
>
>
As said above, _any_ statistic will do at this point.

>>> How important are the mentioned functions for you within the Linux
>>> programming interface so far?
>>>
>> Not very. The interface is only used in a slow path, and the execution
>> time doesn't affect I/O performance in any way.
>
> Thanks for another interesting information.
>
>
>>>> Case in point: with your patch the x86_64 compiler generates nearly
>>>> identical code for driver/md/raid1.c, but with one instruction _more_
>>>> after your patch has been applied.
>>>
>>> Which software versions and command parameters did you try out
>>> for this information (from an unspecified run time environment)?
>>>
>> # gcc --version
>> gcc (SUSE Linux) 4.8.5
>
> Thanks for this detail.
>
> * Did you choose any special optimisation settings for your quick check?
>
> * Will any compilation results matter if "optimisation" would be
> switched off there?
>
>
These were the results when calling 'make' in the kernel source tree.
With all applicable options.

>> I'm still waiting from results from your side.
>
> Would any other software developers or testers dare to add related information?
>
No. It's your patch, _you_ have to do it.

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
[email protected] +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: F. Imend?rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N?rnberg)

2016-10-17 14:31:37

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>> Am I the only software developer so far who would dare to reconsider
>> implementation details from three status functions?
>>
> No.

Thanks for this kind of promising feedback.


> But we're waiting for you showing is that it is an improvement.

Can this aspect also be clarified to some degree from a logical point of view?

* Would you really like to know under which circumstances data processing
will be faster for a single character instead of using a string pointer
and corresponding two characters?

* Do you care for a changed memory allocation characteristic?

* Will it occasionally be useful to avoid the storage for another string literal?

Regards,
Markus

2016-10-17 15:33:44

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 04:30 PM, SF Markus Elfring wrote:
>>> Am I the only software developer so far who would dare to reconsider
>>> implementation details from three status functions?
>>>
>> No.
>
> Thanks for this kind of promising feedback.
>
>
>> But we're waiting for you showing is that it is an improvement.
>
> Can this aspect also be clarified to some degree from a logical point of view?
>
I sincerely doubt that.
We've discussed the logical implications already, and failed to come to
a consensus. So we need some proof (as in: on this architecture I'm
seeing this and that performance improvements).
Which you have to deliver.

> * Would you really like to know under which circumstances data processing
> will be faster for a single character instead of using a string pointer
> and corresponding two characters?
>
It's not a problem of the interface, it's a problem of the resulting
code (ie assembler output). We can discuss all we like, if the compiler
decides to throw in an optimisation none of the arguments even apply.

> * Do you care for a changed memory allocation characteristic?
>
> * Will it occasionally be useful to avoid the storage for another string literal?
>
Occasionally: yes.
In this particular case: hardly.

Cheers,

Hannes
--
Dr. Hannes Reinecke zSeries & Storage
[email protected] +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

2016-10-17 16:09:12

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>> * Would you really like to know under which circumstances data processing
>> will be faster for a single character instead of using a string pointer
>> and corresponding two characters?
>>
> It's not a problem of the interface, it's a problem of the resulting code
> (ie assembler output).

How do you think about to discuss concrete generated code any further?


> We can discuss all we like, if the compiler decides to throw in
> an optimisation none of the arguments even apply.

Would it make sense to clarify assembler output with optimisation switched off?

Do you eventually care for code from non-optimising compilers?


>> * Will it occasionally be useful to avoid the storage for another string literal?
>>
> Occasionally: yes.
> In this particular case: hardly.

I am curious when such a software design aspect can become more relevant.
Would it be nice to get rid of three questionable string terminators (null bytes)
for example?

Regards,
Markus

2016-10-17 17:18:50

by Hannes Reinecke

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

On 10/17/2016 06:08 PM, SF Markus Elfring wrote:
>>> * Would you really like to know under which circumstances data processing
>>> will be faster for a single character instead of using a string pointer
>>> and corresponding two characters?
>>>
>> It's not a problem of the interface, it's a problem of the resulting code
>> (ie assembler output).
>
> How do you think about to discuss concrete generated code any further?
>
Sure. Show me the generated code and point out where the benefits are.

>> We can discuss all we like, if the compiler decides to throw in
>> an optimisation none of the arguments even apply.
>
> Would it make sense to clarify assembler output with optimisation switched off?
>
> Do you eventually care for code from non-optimising compilers?
>
No. This is the linux kernel. There is a very, _very_ limited benefit of
trying to use a non-standard compiler.

>
>>> * Will it occasionally be useful to avoid the storage for another string literal?
>>>
>> Occasionally: yes.
>> In this particular case: hardly.
>
> I am curious when such a software design aspect can become more relevant.
> Would it be nice to get rid of three questionable string terminators (null bytes)
> for example?
>
Again, all this does it trying to out-guess what the compiler might be
doing during compilation. For which the easiest method is checking.
So back to the original task for you: Show me in the generated output
where the benefits are.

Cheers,

Hannes
--
Dr. Hannes Reinecke zSeries & Storage
[email protected] +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

2016-10-18 18:21:53

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

> So back to the original task for you: Show me in the generated output where the benefits are.

I can offer a bit more information for this software development discussion.


The afffected source files can be compiled for the processor architecture "x86_64"
by a tool like "GCC 6.2.1+r239849-1.3" from the software distribution
"openSUSE Tumbleweed" with the following command examples.

git checkout next-20161014 && my_cc=/usr/bin/gcc-6 && make HOSTCC="${my_cc}" allmodconfig && make -j6 HOSTCC="${my_cc}" drivers/md/
git checkout next_usage_of_seq_putc_in_md_raid_1 && my_cc=/usr/bin/gcc-6 && make HOSTCC="${my_cc}" allmodconfig && make -j6 HOSTCC="${my_cc}" drivers/md/


The tool "objdump" from the software package "binutils 2.27-1.3" can be used
to get corresponding disassemblies for a file like "drivers/md/raid1.obj"
which can then be compared as follows.


--- ../disassembly-md-raid1-next-20161014-1.txt 2016-10-18 18:00:12.341222741 +0200
+++ ../disassembly-md-raid1-seq_putc-1.txt 2016-10-18 18:03:54.135887333 +0200
@@ -3349,7 +3349,7 @@
37ad: 85 c0 test %eax,%eax
37af: 74 0d je 37be <raid1_status+0x9e>
37b1: 80 3d 00 00 00 00 00 cmpb $0x0,0x0(%rip) # 37b8 <raid1_status+0x98>
- 37b8: 0f 84 1d 01 00 00 je 38db <raid1_status+0x1bb>
+ 37b8: 0f 84 1b 01 00 00 je 38d9 <raid1_status+0x1b9>
37be: 4c 89 ff mov %r15,%rdi
37c1: 31 db xor %ebx,%ebx
37c3: e8 00 00 00 00 callq 37c8 <raid1_status+0xa8>
@@ -3404,42 +3404,43 @@
3891: 85 c0 test %eax,%eax
3893: 74 09 je 389e <raid1_status+0x17e>
3895: 80 3d 00 00 00 00 00 cmpb $0x0,0x0(%rip) # 389c <raid1_status+0x17c>
- 389c: 74 6e je 390c <raid1_status+0x1ec>
+ 389c: 74 6c je 390a <raid1_status+0x1ea>
389e: 48 c7 c2 00 00 00 00 mov $0x0,%rdx
38a5: be 01 00 00 00 mov $0x1,%esi
38aa: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
38b1: 65 ff 0d 00 00 00 00 decl %gs:0x0(%rip) # 38b8 <raid1_status+0x198>
38b8: e8 00 00 00 00 callq 38bd <raid1_status+0x19d>
38bd: 4c 89 f7 mov %r14,%rdi
- 38c0: 48 c7 c6 00 00 00 00 mov $0x0,%rsi
- 38c7: e8 00 00 00 00 callq 38cc <raid1_status+0x1ac>
- 38cc: 48 83 c4 10 add $0x10,%rsp
- 38d0: 5b pop %rbx
- 38d1: 41 5c pop %r12
- 38d3: 41 5d pop %r13
- 38d5: 41 5e pop %r14
- 38d7: 41 5f pop %r15
- 38d9: 5d pop %rbp
- 38da: c3 retq
- 38db: e8 00 00 00 00 callq 38e0 <raid1_status+0x1c0>
- 38e0: 84 c0 test %al,%al
- 38e2: 0f 85 d6 fe ff ff jne 37be <raid1_status+0x9e>
- 38e8: 48 c7 c2 00 00 00 00 mov $0x0,%rdx
- 38ef: be 69 03 00 00 mov $0x369,%esi
- 38f4: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
- 38fb: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 3902 <raid1_status+0x1e2>
- 3902: e8 00 00 00 00 callq 3907 <raid1_status+0x1e7>
- 3907: e9 b2 fe ff ff jmpq 37be <raid1_status+0x9e>
- 390c: e8 00 00 00 00 callq 3911 <raid1_status+0x1f1>
- 3911: 84 c0 test %al,%al
- 3913: 75 89 jne 389e <raid1_status+0x17e>
- 3915: 48 c7 c2 00 00 00 00 mov $0x0,%rdx
- 391c: be 9c 03 00 00 mov $0x39c,%esi
- 3921: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
- 3928: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 392f <raid1_status+0x20f>
- 392f: e8 00 00 00 00 callq 3934 <raid1_status+0x214>
- 3934: e9 65 ff ff ff jmpq 389e <raid1_status+0x17e>
- 3939: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
+ 38c0: be 5d 00 00 00 mov $0x5d,%esi
+ 38c5: e8 00 00 00 00 callq 38ca <raid1_status+0x1aa>
+ 38ca: 48 83 c4 10 add $0x10,%rsp
+ 38ce: 5b pop %rbx
+ 38cf: 41 5c pop %r12
+ 38d1: 41 5d pop %r13
+ 38d3: 41 5e pop %r14
+ 38d5: 41 5f pop %r15
+ 38d7: 5d pop %rbp
+ 38d8: c3 retq
+ 38d9: e8 00 00 00 00 callq 38de <raid1_status+0x1be>
+ 38de: 84 c0 test %al,%al
+ 38e0: 0f 85 d8 fe ff ff jne 37be <raid1_status+0x9e>
+ 38e6: 48 c7 c2 00 00 00 00 mov $0x0,%rdx
+ 38ed: be 69 03 00 00 mov $0x369,%esi
+ 38f2: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
+ 38f9: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 3900 <raid1_status+0x1e0>
+ 3900: e8 00 00 00 00 callq 3905 <raid1_status+0x1e5>
+ 3905: e9 b4 fe ff ff jmpq 37be <raid1_status+0x9e>
+ 390a: e8 00 00 00 00 callq 390f <raid1_status+0x1ef>
+ 390f: 84 c0 test %al,%al
+ 3911: 75 8b jne 389e <raid1_status+0x17e>
+ 3913: 48 c7 c2 00 00 00 00 mov $0x0,%rdx
+ 391a: be 9c 03 00 00 mov $0x39c,%esi
+ 391f: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
+ 3926: c6 05 00 00 00 00 01 movb $0x1,0x0(%rip) # 392d <raid1_status+0x20d>
+ 392d: e8 00 00 00 00 callq 3932 <raid1_status+0x212>
+ 3932: e9 67 ff ff ff jmpq 389e <raid1_status+0x17e>
+ 3937: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
+ 393e: 00 00

0000000000003940 <print_conf>:
3940: e8 00 00 00 00 callq 3945 <print_conf+0x5>
@@ -11134,7 +11135,7 @@

0000000000000000 <_GLOBAL__sub_D_65535_0_raid1.c>:
0: 55 push %rbp
- 1: be 35 00 00 00 mov $0x35,%esi
+ 1: be 34 00 00 00 mov $0x34,%esi
6: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
d: 48 89 e5 mov %rsp,%rbp
10: e8 00 00 00 00 callq 15 <_GLOBAL__sub_D_65535_0_raid1.c+0x15>
@@ -11145,7 +11146,7 @@

0000000000000000 <_GLOBAL__sub_I_65535_1_raid1.c>:
0: 55 push %rbp
- 1: be 35 00 00 00 mov $0x35,%esi
+ 1: be 34 00 00 00 mov $0x34,%esi
6: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
d: 48 89 e5 mov %rsp,%rbp
10: e8 00 00 00 00 callq 15 <_GLOBAL__sub_I_65535_1_raid1.c+0x15>


Does this kind of data display contain differences which are worth for further considerations?

Regards,
Markus

2016-10-19 14:11:27

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()

>> * How do you think about to avoid a variable assignment in case
>> that this memory allocation failed anyhow?
>
> There is no memory allocation that can fail at this point.

Do you really know the failure probability for a call of the
function "kmalloc" (within the function "wbcir_tx") under all
possible run time situations?


>> * Do you care for data access locality?
>
> Not unless you can show measurable performance improvements?

Did any software developer (before me) dare anything in this direction?

Regards,
Markus

2016-10-19 14:14:28

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

>>>> Move the setting for the local variables "mask", "match" and "rc6_csl"
>>>> behind the source code for a condition check by this function
>>>> at the beginning.
>>>
>>> Again, I can't see what the point is?
>>
>> * How do you think about to set these variables only after the initial
>> check succeded?
>
> I prefer setting variables early so that no thinking about
> whether they're initialized or not is necessary later.

* How do you think about to reduce the scope for these variables then?

* Would you dare to move the corresponding source code into a separate function?

Regards,
Markus

2016-10-19 14:18:02

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move a variable assignment in two functions

>> Move the assignment for the local variable "data" behind the source code
>> for condition checks by these functions.
>
> Why?

* Would you like to set these variables only after the initial
check succeeded?

* Do you care for data access locality also in these cases?

Regards,
Markus

2016-10-19 14:20:31

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

>> Move the setting for the local variables "mask", "match" and "rc6_csl"
>> behind the source code for a condition check by this function
>> at the beginning.
>
> Again, I can't see what the point is?

* How do you think about to set these variables only after the initial
check succeded?

* Do you care for data access locality?

Regards,
Markus

2016-10-19 14:26:29

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

October 14, 2016 1:43 PM, "SF Markus Elfring" <[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 14 Oct 2016 10:40:12 +0200
>
> Move the setting for the local variables "mask", "match" and "rc6_csl"
> behind the source code for a condition check by this function
> at the beginning.

Again, I can't see what the point is?

> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/winbond-cir.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index fd997f0..9d05e17 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)
> bool do_wake = true;
> u8 match[11];
> u8 mask[11];
> - u8 rc6_csl = 0;
> + u8 rc6_csl;
> int i;
>
> - memset(match, 0, sizeof(match));
> - memset(mask, 0, sizeof(mask));
> -
> if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
> do_wake = false;
> goto finish;
> }
>
> + rc6_csl = 0;
> + memset(match, 0, sizeof(match));
> + memset(mask, 0, sizeof(mask));
> switch (protocol) {
> case IR_PROTOCOL_RC5:
> if (wake_sc > 0xFFF) {
> --
> 2.10.1

2016-10-19 14:26:27

by David Härdeman

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()

October 19, 2016 3:32 PM, "SF Markus Elfring" <[email protected]> wrote:
>>> Move the assignment for the local variable "data" behind the source code
>>> for a memory allocation by this function.
>>
>> Sorry, I can't see what the point is?
>
> * How do you think about to avoid a variable assignment in case
> that this memory allocation failed anyhow?

There is no memory allocation that can fail at this point.

> * Do you care for data access locality?

Not unless you can show measurable performance improvements?

2016-10-19 14:26:24

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

October 15, 2016 6:42 PM, "SF Markus Elfring" <[email protected]> wrote:
>>> + /* Set CEIR_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>>> +set_irqmask:
>>> /*
>>> * ACPI will set the HW disable bit for SP3 which means that the
>>> * output signals are left in an undefined state which may cause
>>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>>> */
>>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>>> disable_irq(data->irq);
>>> + return;
>>> +clear_bits:
>>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>>> +
>>> + /* Clear CEIR_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>>> + goto set_irqmask;
>>
>> I'm not convinced that adding a goto which goes backwards is making this
>> code any more readible, just so that a local variable can be dropped.
>
> Thanks for your feedback.
>
> Is such a "backward jump" usual and finally required when you would like
> to move a bit of common error handling code to the end without using extra
> local variables and a few statements should still be performed after it?
>

I'm sorry, I can't parse this.

2016-10-19 14:29:14

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions

October 14, 2016 1:45 PM, "SF Markus Elfring" <[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 14 Oct 2016 13:13:11 +0200
>
> Move the assignment for the local variable "data" behind the source code
> for condition checks by these functions.

Why?

> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/winbond-cir.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 3d286b9..716b1fe 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)
> static int
> wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned long flags;
> u8 val;
> u32 freq;
> @@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> break;
> }
>
> + data = dev->priv;
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> spin_unlock_irqrestore(&data->spinlock, flags);
> @@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> static int
> wbcir_txmask(struct rc_dev *dev, u32 mask)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned long flags;
> u8 val;
>
> @@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
> return -EINVAL;
> }
>
> + data = dev->priv;
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> spin_unlock_irqrestore(&data->spinlock, flags);
> --
> 2.10.1

2016-10-19 14:29:12

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

October 15, 2016 3:30 PM, "Sean Young" <[email protected]> wrote:
> On Fri, Oct 14, 2016 at 01:44:02PM +0200, SF Markus Elfring wrote:
>
>> From: Markus Elfring <[email protected]>
>> Date: Fri, 14 Oct 2016 12:48:41 +0200
>>
>> The local variable "do_wake" was set to "false" after an invalid system
>> setting was detected so that a bit of error handling was triggered.
>>
>> * Replace these assignments by direct jumps to the source code with the
>> desired exception handling.
>>
>> * Delete this status variable and a corresponding check which became
>> unnecessary with this refactoring.
>>
>> Signed-off-by: Markus Elfring <[email protected]>
>> ---
>> drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
>> 1 file changed, 34 insertions(+), 44 deletions(-)
>>
>> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
>> index 9d05e17..3d286b9 100644
>> --- a/drivers/media/rc/winbond-cir.c
>> +++ b/drivers/media/rc/winbond-cir.c
>> @@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
>> {
>> struct device *dev = &device->dev;
>> struct wbcir_data *data = pnp_get_drvdata(device);
>> - bool do_wake = true;
>> u8 match[11];
>> u8 mask[11];
>> u8 rc6_csl;
>> int i;
>>
>> - if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
>> - do_wake = false;
>> - goto finish;
>> - }
>> + if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
>> + goto clear_bits;
>>
>> rc6_csl = 0;
>> memset(match, 0, sizeof(match));
>> @@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> switch (protocol) {
>> case IR_PROTOCOL_RC5:
>> if (wake_sc > 0xFFF) {
>> - do_wake = false;
>> dev_err(dev, "RC5 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>>
>> /* Mask = 13 bits, ex toggle */
>> @@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)
>>
>> case IR_PROTOCOL_NEC:
>> if (wake_sc > 0xFFFFFF) {
>> - do_wake = false;
>> dev_err(dev, "NEC - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>>
>> mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
>> @@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)
>>
>> if (wake_rc6mode == 0) {
>> if (wake_sc > 0xFFFF) {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>>
>> /* Command */
>> @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> } else if (wake_sc <= 0x007FFFFF) {
>> rc6_csl = 60;
>> } else {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>>
>> /* Header */
>> @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
>> mask[i++] = 0x0F;
>>
>> } else {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake mode\n");
>> + goto clear_bits;
>> }
>>
>> break;
>>
>> default:
>> - do_wake = false;
>> - break;
>> + goto clear_bits;
>> }
>>
>> -finish:
>> - if (do_wake) {
>> - /* Set compare and compare mask */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> - WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
>> - 0x3F);
>> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> - WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
>> - 0x3F);
>> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>> -
>> - /* RC6 Compare String Len */
>> - outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>> -
>> - /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>> + /* Set compare and compare mask */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> + WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
>> + 0x3F);
>> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> + WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
>> + 0x3F);
>> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>>
>> - /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>> + /* RC6 Compare String Len */
>> + outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>>
>> - /* Set CEIR_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> -
>> - } else {
>> - /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> + /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>>
>> - /* Clear CEIR_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> - }
>> + /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>>
>> + /* Set CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> +set_irqmask:
>> /*
>> * ACPI will set the HW disable bit for SP3 which means that the
>> * output signals are left in an undefined state which may cause
>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>> */
>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>> disable_irq(data->irq);
>> + return;
>> +clear_bits:
>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> +
>> + /* Clear CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> + goto set_irqmask;
>
> I'm not convinced that adding a goto which goes backwards is making this
> code any more readible, just so that a local variable can be dropped.
>

Agreed.

2016-10-19 15:31:23

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()

October 14, 2016 1:41 PM, "SF Markus Elfring" <[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 14 Oct 2016 07:19:00 +0200
>
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Sure...why not...

Signed-off-by: David Härdeman <[email protected]>


> ---
> drivers/media/rc/winbond-cir.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 95ae60e..59050f5 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> unsigned i;
> unsigned long flags;
>
> - buf = kmalloc(count * sizeof(*b), GFP_KERNEL);
> + buf = kmalloc_array(count, sizeof(*b), GFP_KERNEL);
> if (!buf)
> return -ENOMEM;
>
> --
> 2.10.1

2016-10-19 15:36:22

by David Härdeman

[permalink] [raw]
Subject: Re: [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()

October 14, 2016 1:42 PM, "SF Markus Elfring" <[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 14 Oct 2016 07:34:46 +0200
>
> Move the assignment for the local variable "data" behind the source code
> for a memory allocation by this function.

Sorry, I can't see what the point is?


> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/winbond-cir.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 59050f5..fd997f0 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
> static int
> wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned *buf;
> unsigned i;
> unsigned long flags;
> @@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> for (i = 0; i < count; i++)
> buf[i] = DIV_ROUND_CLOSEST(b[i], 10);
>
> + data = dev->priv;
> /* Not sure if this is possible, but better safe than sorry */
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> --
> 2.10.1

2016-10-19 15:49:02

by David Härdeman

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

October 19, 2016 3:38 PM, "SF Markus Elfring" <[email protected]> wrote:
>>> Move the setting for the local variables "mask", "match" and "rc6_csl"
>>> behind the source code for a condition check by this function
>>> at the beginning.
>>
>> Again, I can't see what the point is?
>
> * How do you think about to set these variables only after the initial
> check succeded?

I prefer setting variables early so that no thinking about whether they're initialized or not is necessary later.

> * Do you care for data access locality?

Not unless you can show measurable performance improvements?

2016-10-19 16:23:36

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

>>>> + /* Set CEIR_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>>>> +set_irqmask:
>>>> /*
>>>> * ACPI will set the HW disable bit for SP3 which means that the
>>>> * output signals are left in an undefined state which may cause
>>>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>>>> */
>>>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>>>> disable_irq(data->irq);
>>>> + return;
>>>> +clear_bits:
>>>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>>>> +
>>>> + /* Clear CEIR_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>>>> + goto set_irqmask;
>>>
>>> I'm not convinced that adding a goto which goes backwards is making this
>>> code any more readible, just so that a local variable can be dropped.
>>
>> Thanks for your feedback.
>>
>> Is such a "backward jump" usual and finally required when you would like
>> to move a bit of common error handling code to the end without using extra
>> local variables and a few statements should still be performed after it?
>>
>
> I'm sorry, I can't parse this.

Can an other update suggestion like "[PATCH 6/6] crypto-caamhash:
Move common error handling code in two functions" explain this technique
a bit better in principle?
https://patchwork.kernel.org/patch/9333861/
https://lkml.kernel.org/r/<[email protected]>

Regards,
Markus

2016-10-19 14:14:26

by SF Markus Elfring

[permalink] [raw]
Subject: Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()

>> Move the assignment for the local variable "data" behind the source code
>> for a memory allocation by this function.
>
> Sorry, I can't see what the point is?

* How do you think about to avoid a variable assignment in case
that this memory allocation failed anyhow?

* Do you care for data access locality?

Regards,
Markus

2016-10-20 12:25:58

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>> So back to the original task for you: Show me in the generated output where the benefits are.

I can offer another bit of information for this software development discussion.

The following build settings were active in my "Makefile" for this Linux test case.


HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89



The afffected source files can be compiled for the processor architecture "x86_64"
by a tool like "GCC 6.2.1+r239849-1.4" from the software distribution
"openSUSE Tumbleweed" with the following command example.

my_original=${my_build_dir}unchanged/test/ \
&& my_fixing=${my_build_dir}patched/test/ \
&& mkdir -p ${my_original} ${my_fixing} \
&& my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/md/raid1.s \
&& git checkout next-20161014 \
&& make -j6 O="${my_original}" HOSTCC="${my_cc}" allmodconfig ${my_module} \
&& git checkout next_usage_of_seq_putc_in_md_raid_1 \
&& make -j6 O="${my_fixing}" HOSTCC="${my_cc}" allmodconfig ${my_module} \
&& diff -u "${my_original}${my_module}" "${my_fixing}${my_module}" > "${my_build_dir}assembler_code_comparison_$(date -I)_1.diff"


Unfortunately, the generated file got the size "311 KiB". I guess that
this is too big to send such a file around on the Linux mailing list.

Is this kind of assembler code comparison still useful to clarify relevant
differences further?

Regards,
Markus

2016-10-28 20:05:35

by SF Markus Elfring

[permalink] [raw]
Subject: Re: MD-RAID: Use seq_putc() in three status functions?

>>> So back to the original task for you: Show me in the generated output where the benefits are.

I can offer another bit of information for this software development discussion.

The following build settings were active in my "Makefile" for this Linux test case.


HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89



The afffected source files can be compiled for the processor architecture "x86_64"
by a tool like "GCC 6.2.1+r239849-1.5" from the software distribution
"openSUSE Tumbleweed" with the following command example.

my_original=${my_build_dir}unchanged/test/ \
&& my_fixing=${my_build_dir}patched/test/ \
&& mkdir -p ${my_original} ${my_fixing} \
&& my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/md/raid1.s \
&& git checkout next-20161014 \
&& make -j6 O="${my_original}" CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& git checkout next_usage_of_seq_putc_in_md_raid_1 \
&& make -j6 O="${my_fixing}" CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& diff -u "${my_original}${my_module}" "${my_fixing}${my_module}" > "${my_build_dir}assembler_code_comparison_$(date -I)_3.diff"


The generated file got the size "25.4 KiB" this time. I guess that only
the following two diff hunks are interesting then to show desired effects
for the suggested software refactoring around data output of a single character
(instead of a similar string).



@@ -4402,10 +4402,6 @@
.LC19:
.string "%s"
.zero 61
- .align 32
-.LC20:
- .string "]"
- .zero 62
.text
.p2align 4,,15
.type raid1_status, @function
@@ -4564,8 +4560,8 @@
movq $rcu_lock_map, %rdi #,
call lock_release #
movq %r14, %rdi # seq,
- movq $.LC20, %rsi #,
- call seq_printf #
+ movl $93, %esi #,
+ call seq_putc #
addq $16, %rsp #,
popq %rbx #
popq %r12 #



* Is this kind of assembler code comparison useful to clarify relevant
differences further?

* Are any software development concerns left over for such a transformation?

Regards,
Markus

2016-11-18 12:52:52

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()

Em Thu, 13 Oct 2016 18:42:16 +0200
SF Markus Elfring <[email protected]> escreveu:

> From: Markus Elfring <[email protected]>
> Date: Thu, 13 Oct 2016 15:00:12 +0200
>
> Adjust a jump label according to the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/media/rc/redrat3.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
> index 74d93dd..055f214 100644
> --- a/drivers/media/rc/redrat3.c
> +++ b/drivers/media/rc/redrat3.c
> @@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
> ret = rc_register_device(rc);
> if (ret < 0) {
> dev_err(rr3->dev, "remote dev registration failed\n");
> - goto out;
> + goto free_device;
> }
>
> return rc;
> -
> -out:
> +free_device:
> rc_free_device(rc);
> return NULL;
> }

I don't see *any* sense on patches like this. Please don't flood me with
useless patches like that.

I'll silently ignore any patches like this during my review.

Regards,
Mauro



Thanks,
Mauro

2016-11-18 13:01:09

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()

Em Fri, 18 Nov 2016 10:52:40 -0200
Mauro Carvalho Chehab <[email protected]> escreveu:

> Em Thu, 13 Oct 2016 18:42:16 +0200
> SF Markus Elfring <[email protected]> escreveu:
>
> > From: Markus Elfring <[email protected]>
> > Date: Thu, 13 Oct 2016 15:00:12 +0200
> >
> > Adjust a jump label according to the Linux coding style convention.
> >
> > Signed-off-by: Markus Elfring <[email protected]>
> > ---
> > drivers/media/rc/redrat3.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
> > index 74d93dd..055f214 100644
> > --- a/drivers/media/rc/redrat3.c
> > +++ b/drivers/media/rc/redrat3.c
> > @@ -890,12 +890,11 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
> > ret = rc_register_device(rc);
> > if (ret < 0) {
> > dev_err(rr3->dev, "remote dev registration failed\n");
> > - goto out;
> > + goto free_device;
> > }
> >
> > return rc;
> > -
> > -out:
> > +free_device:
> > rc_free_device(rc);
> > return NULL;
> > }
>
> I don't see *any* sense on patches like this. Please don't flood me with
> useless patches like that.
>
> I'll silently ignore any patches like this during my review.

Btw:
[PATCH 14/18] [media] RedRat3: Rename a jump label in redrat3_init_rc_dev()

Don't use CamelCase for the name of the driver. We don't use CamelCase
inside the Kernel, as it violates its coding style. Also, it means
nothing, as the name of this driver, and its c file is "redhat3".

Thanks,
Mauro

2018-01-13 08:55:16

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH v2] md-multipath: Use seq_putc() in multipath_status()

From: Markus Elfring <[email protected]>
Date: Sat, 13 Jan 2018 09:49:03 +0100

A single character (closing square bracket) should be put into a sequence.
Thus use the corresponding function "seq_putc".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/md/md-multipath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-multipath.c b/drivers/md/md-multipath.c
index e40065bdbfc8..0a7e99d62c69 100644
--- a/drivers/md/md-multipath.c
+++ b/drivers/md/md-multipath.c
@@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)
seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
}
rcu_read_unlock();
- seq_printf (seq, "]");
+ seq_putc(seq, ']');
}

static int multipath_congested(struct mddev *mddev, int bits)
--
2.15.1

2018-02-17 21:46:24

by Shaohua Li

[permalink] [raw]
Subject: Re: [PATCH v2] md-multipath: Use seq_putc() in multipath_status()

On Sat, Jan 13, 2018 at 09:55:08AM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 13 Jan 2018 09:49:03 +0100
>
> A single character (closing square bracket) should be put into a sequence.
> Thus use the corresponding function "seq_putc".
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
applied, thanks
> ---
> drivers/md/md-multipath.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/md/md-multipath.c b/drivers/md/md-multipath.c
> index e40065bdbfc8..0a7e99d62c69 100644
> --- a/drivers/md/md-multipath.c
> +++ b/drivers/md/md-multipath.c
> @@ -157,7 +157,7 @@ static void multipath_status(struct seq_file *seq, struct mddev *mddev)
> seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
> }
> rcu_read_unlock();
> - seq_printf (seq, "]");
> + seq_putc(seq, ']');
> }
>
> static int multipath_congested(struct mddev *mddev, int bits)
> --
> 2.15.1
>