Source code review around jump label usage
Subsystems (101)
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
Quoted 3 lines
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
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
Quoted 14 lines · SF Markus Elfring
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 ║
Quoted 9 lines
║ 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
cover block: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/block/zram/zram_drv.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/block/zram/zram_drv.c +13 -13
@@ -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; }
Signature · 1 line
2.6.3
PATCH 2/2 z2ram: Delete a jump label in z2_init()
In reply to SF Markus ElfringFrom: 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.
--- drivers/block/z2ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/z2ram.c +1 -3
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 uinput: Rename a jump label in uinput_ioctl_handler()
In reply to SF Markus ElfringFrom: 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.
--- drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-)
drivers/input/misc/uinput.c +33 -33
@@ -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; }
Signature · 1 line
2.6.3
cover iSCSI-target: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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".
--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -2
@@ -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;
Signature · 1 line
2.6.3
PATCH 2/7 iscsi-target: Less checks in iscsi_set_default_param() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +10 -11
@@ -131,20 +131,20 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *paraif (!param) {pr_err ("Unable to allocate memory for parameter.\n" ); - goto out; +return NULL ; }INIT_LIST_HEAD (¶m->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 *paradefault :pr_err ("Unknown type_range 0x%02x\n" , param->type_range); - goto out; + goto free_value; }list_add_tail (¶m->p_list, ¶m_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 ; }
Signature · 1 line
2.6.3
PATCH 3/7 iscsi-target: Delete an unnecessary variable initialisation in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -1
@@ -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 );
Signature · 1 line
2.6.3
PATCH 4/7 iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -2
@@ -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" );
Signature · 1 line
2.6.3
PATCH 5/7 iscsi-target: Rename a jump label in iscsi_create_default_params()
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 64 +++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +32 -32
@@ -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 ; }
Signature · 1 line
2.6.3
PATCH 6/7 iscsi-target: Delete unnecessary variable initialisations in iscsi_check_valuelist_for_support()
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -1
@@ -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;
Signature · 1 line
2.6.3
PATCH 7/7 iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()
In reply to SF Markus ElfringFrom: 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.
--- drivers/target/iscsi/iscsi_target_parameters.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/target/iscsi/iscsi_target_parameters.c +1 -4
@@ -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)
Signature · 1 line
2.6.3
Re: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
In reply to SF Markus ElfringQuoted 22 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 13:44:06 +0100The 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(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c free_param: · line 205
Quoted 7 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -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
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c +0
-1if (!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
Re: [PATCH 4/7] iscsi-target: Make a variable initialisation a bit more obvious in iscsi_create_default_params()
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c free_param: · line 205
Quoted 8 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -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
Re: [PATCH 7/7] iscsi-target: Make two variable initialisations a bit more obvious in iscsi_check_valuelist_for_support()
In reply to SF Markus ElfringAm 12.12.2015 15:45, schrieb SF Markus Elfring:
Quoted 18 lines
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 15:04:57 +0100The 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(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c static char *iscsi_check_valuelist_for_support( · line 925
Quoted 9 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-4@@ -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
Quoted 2 lines
drivers/target/iscsi/iscsi_target_parameters.c +0
-0do { if (!proposer_values)
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
In reply to SF Markus ElfringQuoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100Omit 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(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0
drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 10 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -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
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
Quoted 15 lines
drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 11 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -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.
Quoted 3 lines
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.
Quoted 1 line
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"?
Quoted 1 line
It's like a new paragraph.
I do not see the separation in a strict way so far.
Quoted 1 line
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
Dmitry Torokhov
maintainerRe: [PATCH] uinput: Rename a jump label in uinput_ioctl_handler()
In reply to SF Markus ElfringHi Markus,
Quoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 10:06:00 +0100This 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.
Quoted 214 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/input/misc/uinput.c | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-)drivers/input/misc/uinput.c +33
-33@@ -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; }Signature · 1 line
2.6.3
Signature · 1 line
Dmitry
cover staging-Lustre: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/staging/lustre/lustre/llite/namei.c | 1 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ------- 2 files changed, 8 deletions(-)
drivers/staging/lustre/lustre/llite/namei.c +0 -1
@@ -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);
drivers/staging/lustre/lustre/mdc/mdc_request.c +0 -7
@@ -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;
Signature · 1 line
2.6.3
PATCH 2/7 staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to SF Markus ElfringFrom: 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
}
--- 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(-)
drivers/staging/lustre/lustre/llite/file.c +13 -13
@@ -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; }
drivers/staging/lustre/lustre/llite/namei.c +6 -6
@@ -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; }
drivers/staging/lustre/lustre/llite/xattr.c +10 -10
@@ -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;
drivers/staging/lustre/lustre/mdc/mdc_request.c +27 -27
203 lines not on this page · raw message
drivers/staging/lustre/lustre/osc/osc_request.c +14 -14
@@ -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 )) {
drivers/staging/lustre/lustre/ptlrpc/llog_client.c +11 -11
@@ -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);
Signature · 1 line
2.6.3
PATCH 3/7 staging: lustre: Rename a jump label for a kfree(key) call
In reply to SF Markus ElfringFrom: 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.
--- drivers/staging/lustre/lustre/mdc/mdc_request.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/mdc/mdc_request.c +5 -6
@@ -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; }
Signature · 1 line
2.6.3
PATCH 4/7 staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: 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.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -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;
Signature · 1 line
2.6.3
PATCH 5/7 staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +12 -13
@@ -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; }
Signature · 1 line
2.6.3
PATCH 6/7 staging: lustre: A few checks less in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 32 +++++++++++-------------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +14 -18
@@ -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 ;
Signature · 1 line
2.6.3
PATCH 7/7 staging: lustre: Rename a jump label for module_put() calls
In reply to SF Markus ElfringFrom: 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
}
--- 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(-)
drivers/staging/lustre/lustre/llite/lloop.c +4 -4
@@ -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;
drivers/staging/lustre/lustre/mdc/mdc_request.c +26 -26
144 lines not on this page · raw message
drivers/staging/lustre/lustre/osc/osc_request.c +12 -12
@@ -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; }
Signature · 1 line
2.6.3
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
In reply to SF Markus ElfringOn (12/11/15 19:24), SF Markus Elfring wrote:
[..]
Quoted 17 lines
drivers/block/zram/zram_drv.c +2
-2@@ -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;
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 668
Quoted 9 lines
drivers/block/zram/zram_drv.c +2
-4@@ -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.
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 671
Quoted 4 lines
drivers/block/zram/zram_drv.c +1
-1ret =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.
Quoted 42 lines
drivers/block/zram/zram_drv.c +4
-4} 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);
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 769
Quoted 10 lines
drivers/block/zram/zram_drv.c +4
-2atomic64_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.
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 771
Quoted 2 lines
drivers/block/zram/zram_drv.c +0
-0return ret; }
-ss
Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()
In reply to SF Markus ElfringCc Jens, Andrew, Geert
Quoted 28 lines · SF Markus Elfring
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(-)drivers/block/z2ram.c +1
-2@@ -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 );
drivers/block/z2ram.c out_queue: · line 377
Quoted 6 lines
drivers/block/z2ram.c +0
-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
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to SF Markus ElfringMarkus, please stop sending these things to rename out labels unless there is a bug. CodingStyle allows out labels.
regards,
dan carpenter
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
In reply to Sergey SenozhatskyQuoted 15 lines
Quoted 15 lines
drivers/block/zram/zram_drv.c +2
-2@@ -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;
Quoted 13 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 668
Quoted 11 lines
drivers/block/zram/zram_drv.c +2
-4page = 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.
Quoted 6 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 671
Quoted 4 lines
drivers/block/zram/zram_drv.c +1
-1ret =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.
Quoted 1 line
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?
Quoted 1 line
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.
Quoted 7 lines
Quoted 7 lines
drivers/block/zram/zram_drv.c +1
-1@@ -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)
Quoted 8 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, · line 769
Quoted 6 lines
drivers/block/zram/zram_drv.c +3
-1zcomp_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?
Quoted 1 line
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
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
Quoted 2 lines
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
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
In reply to Dan CarpenterQuoted 33 lines · Dan Carpenter
Quoted 18 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 12 Dec 2015 11:36:02 +0100Omit 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(-)drivers/target/iscsi/iscsi_target_parameters.c +0
-0drivers/target/iscsi/iscsi_target_parameters.c static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para · line 134
Quoted 10 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-2@@ -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.
Quoted 7 lines
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
Signature · 10 lines
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 -- 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
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to Dan CarpenterQuoted 2 lines
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
Re: [PATCH 2/2] z2ram: Delete a jump label in z2_init()
In reply to Sergey SenozhatskyQuoted 11 lines · Sergey Senozhatsky
Cc Jens, Andrew, Geert
Quoted 8 lines · SF Markus Elfring
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]>
Quoted 30 lines
Quoted 20 lines
--- drivers/block/z2ram.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/block/z2ram.c +1
-2@@ -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 );drivers/block/z2ram.c out_queue: · line 377
Quoted 6 lines
drivers/block/z2ram.c +0
-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.
Quoted 2 lines
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
Re: [PATCH 2/7] staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
Quoted 2 lines
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.
Quoted 1 line
… 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
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
In reply to SF Markus ElfringOn (12/14/15 07:58), SF Markus Elfring wrote:
[..]
Quoted 4 lines
Quoted 1 line
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
Re: staging: lustre: Rename a jump label for ptlrpc_req_finished() calls
In reply to Dan CarpenterQuoted 11 lines
Quoted 9 lines
Quoted 2 lines
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.
Quoted 1 line
I personally don't agree with them
I guess that my opinion goes into a similar direction here.
Quoted 2 lines
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.
Quoted 4 lines
Quoted 1 line
… 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
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringQuoted 11 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 12:21:17 +0100A 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
Re: [PATCH 1/7] iscsi-target: Use a variable initialisation in iscsi_set_default_param() directly
In reply to Johannes ThumshirnQuoted 12 lines
drivers/target/iscsi/iscsi_target_parameters.c +1
-1@@ -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" );
Quoted 1 line
This way it would be _far_ more readable.
I guess that there are some opinions available for this implementation detail.
Quoted 1 line
IMHO one should have a 1 action per line of code style
How often do you care for such style issues?
Quoted 1 line
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?
Quoted 1 line
But what is the benefit from this? Is it fixing a (hypothetical) bug?
I find the shown null pointer initialisation just needless.
Regards,
Markus
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to Dan CarpenterQuoted 10 lines
Quoted 8 lines
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?
Quoted 1 line
Then in the next patch it moves again.
This detail is a matter of patch granularity.
Quoted 1 line
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
Re: [PATCH 5/7] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 9 lines · SF Markus Elfring
Quoted 9 lines
Quoted 8 lines
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.
Quoted 7 lines
Quoted 1 line
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.
Quoted 9 lines
Quoted 2 lines
Then in the next patch it moves again.
This detail is a matter of patch granularity.
Quoted 1 line
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
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 3 lines
Quoted 1 line
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.
Quoted 4 lines
Quoted 1 line
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
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line
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
Re: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection
In reply to Sergey SenozhatskyQuoted 5 lines
Quoted 2 lines
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 …
Quoted 9 lines
...
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.
Quoted 1 line
no.
Thanks for your feedback.
Regards,
Markus
--
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
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to Dan CarpenterQuoted 3 lines
Quoted 1 line
I do not like patch squashing for my update suggestions here.
I am a maintainer in
drivers/staging.
Thanks for this information.
Quoted 1 line
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?
Quoted 1 line
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
[POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
In reply to SF Markus ElfringFrom: 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.
--- arch/powerpc/boot/fsl-soc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/boot/fsl-soc.c +7 -7
@@ -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; }
Signature · 1 line
2.6.3
Re: [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 14 Dec 2015 23:01:32 +0100A 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
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringQuoted 2 lines · SF Markus Elfring
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."
Quoted 3 lines
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
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six 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.
drivers/staging/lustre/lustre/llite/namei.c
Quoted 1 line
drivers/staging/lustre/lustre/llite/namei.c +0
-0
[]
Quoted 8 lines
drivers/staging/lustre/lustre/llite/namei.c +0
-0@@ -554,7 +554,6 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, retval = NULL;else
retval = dentry;drivers/staging/lustre/lustre/llite/namei.c +0
-1- goto out;out:
if (req)
ptlrpc_req_finished(req);
etc.,,
--
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
Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 10 lines · Joe Perches
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six 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
Re: staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to Dan CarpenterQuoted 1 line
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?
Quoted 1 line
I do not think I have been unfair to you.
This view is correct in principle.
Quoted 1 line
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.)
Quoted 3 lines
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.
Quoted 5 lines
Quoted 4 lines
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.
Quoted 1 line
I do not like the renames.
I guess that this design aspect can be clarified a bit more.
Quoted 2 lines
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.
Quoted 2 lines
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
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
In reply to Dan CarpenterQuoted 8 lines · Dan Carpenter
Quoted 7 lines · Joe Perches
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 13 Dec 2015 09:30:47 +0100Six goto statements referred to a source code position directly behind them. Thus omit such unnecessary jumps.
Quoted 9 lines
Quoted 3 lines
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...
Re: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
Quoted 14 lines · Joe Perches
This is the original code:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); if (result) goto label;
Quoted 3 lines
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
Re: staging: lustre: Delete unnecessary goto statements in six functions
In reply to Joe PerchesQuoted 1 line
This is the original code:
Really …?
Quoted 6 lines
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.
Quoted 3 lines
I don't find the
test->gotolabel; label: use offensive, but if he does, I think keeping a blank line in place of thetest->gotomight be better.
I find this an interesting view on source code layout. Are there any more opinions around such implementation details?
Regards,
Markus
--
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
Joe Perches
maintainerRe: [PATCH 1/7] staging: lustre: Delete unnecessary goto statements in six functions
In reply to Dan CarpenterQuoted 29 lines · Dan Carpenter
Quoted 14 lines · Joe Perches
This is the original code:
result = foo(); if (result) goto label; result = bar(); if (result) goto label; result = baz(); if (result) goto label;Quoted 3 lines
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..
Quoted 2 lines
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
--
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
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
In reply to SF Markus ElfringQuoted 13 lines · SF Markus Elfring
Quoted 1 line
This is the original code:
Really …?
Quoted 6 lines
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.
Quoted 6 lines
Quoted 3 lines
I don't find the
test->gotolabel; label: use offensive, but if he does, I think keeping a blank line in place of thetest->gotomight 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.
--
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
Re: staging: lustre: Delete unnecessary goto statements in six functions
In reply to Joe PerchesQuoted 7 lines
rc = mdc_queue_wait(req); goto out; out: ptlrpc_req_finished(req); return rc; }
Quoted 6 lines
---------------------
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
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 8 lines · SF Markus Elfring
Quoted 8 lines
rc = mdc_queue_wait(req); goto out; out: ptlrpc_req_finished(req); return rc; }---------------------
Quoted 6 lines
Quoted 4 lines
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.
Quoted 1 line
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.
--
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
Re: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 1 line
I think there should _not_ be a hardened rule.
I guess that it can become hard to achieve consensus on a precise rule.
Quoted 1 line
Style is just a guide.
Generally nice …
Quoted 1 line
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
--
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
Joe Perches
maintainerRe: staging: lustre: Delete unnecessary goto statements in six functions
Quoted 2 lines · SF Markus Elfring
Quoted 1 line
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.
Quoted 4 lines
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.
v2 cover staging-Lustre: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/staging/lustre/lustre/llite/namei.c | 1 - drivers/staging/lustre/lustre/mdc/mdc_request.c | 7 ------- 2 files changed, 8 deletions(-)
drivers/staging/lustre/lustre/llite/namei.c +0 -1
@@ -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);
drivers/staging/lustre/lustre/mdc/mdc_request.c +0 -7
@@ -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;
Signature · 1 line
2.6.3
PATCH v2 2/4 staging: lustre: Delete an unnecessary variable initialisation in mgc_process_recover_log()
In reply to SF Markus ElfringFrom: 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.
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -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;
Signature · 1 line
2.6.3
PATCH v2 3/4 staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringFrom: 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".
--- drivers/staging/lustre/lustre/mgc/mgc_request.c | 51 +++++++++++-------------- 1 file changed, 23 insertions(+), 28 deletions(-)
drivers/staging/lustre/lustre/mgc/mgc_request.c +23 -28
@@ -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; }
Signature · 1 line
2.6.3
PATCH v2 4/4 staging: lustre: Fix a jump label position in osc_get_info()
In reply to SF Markus ElfringFrom: 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".
--- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
@@ -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 )) {
Signature · 1 line
2.6.3
Greg Kroah-Hartman
maintainerRe: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to SF Markus ElfringQuoted 14 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100A 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 thealloc_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.
Quoted 7 lines
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
Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
Quoted 5 lines
Quoted 1 line
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
Re: [PATCH v2 3/4] staging: lustre: Less checks in mgc_process_recover_log() after error detection
In reply to Greg Kroah-HartmanQuoted 3 lines · Greg Kroah-Hartman
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.
Quoted 8 lines · SF Markus Elfring
Quoted 7 lines
From: Markus Elfring <[email protected]>
Date: Mon, 21 Dec 2015 18:58:51 +0100A 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 thealloc_page()function failed.
Quoted 6 lines
Quoted 6 lines
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.
Quoted 2 lines
Quoted 2 lines
4. Move an assignment for the variable "eof" behind memory allocations.
I had asked Markus not to do this. It is unrelated.
Quoted 4 lines
Quoted 4 lines
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".
Quoted 2 lines
Quoted 2 lines
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
PATCH 1/1 block-LDM: One function call less in ldm_validate_tocblocks() after error detection
In reply to SF Markus ElfringFrom: 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.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -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 ]));
Signature · 1 line
2.6.3
Re: [PATCH] block-LDM: One function call less in ldm_validate_tocblocks() after error detection
Quoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 22 Dec 2015 22:32:07 +0100This 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(-)block/partitions/ldm.c +0
-0
block/partitions/ldm.c static bool ldm_validate_tocblocks(struct parsed_partitions *state, · line 436
Quoted 5 lines
block/partitions/ldm.c +1
-1@@ -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
Quoted 7 lines
block/partitions/ldm.c +0
-1} tb[2 ] = (struct tocblock *)((u8 *)tb[1 ] +sizeof (*tb[1 ])); tb[3 ] = (struct tocblock *)((u8 *)tb[2 ] +sizeof (*tb[2 ])); --2.6.3
cover 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(-)
Signature · 1 line
2.6.3
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.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -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 ]));
Signature · 1 line
2.6.3
PATCH 2/5 block-LDM: Delete extra log messages for memory allocation failures
In reply to SF Markus ElfringFrom: 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.
--- block/partitions/ldm.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
block/partitions/ldm.c +5 -15
@@ -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))
Signature · 1 line
2.6.3
PATCH 3/5 block-LDM: One function call less in ldm_partition() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 23 Dec 2015 13:32:51 +0100
Let us return directly if a memory allocation failed.
--- block/partitions/ldm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/ldm.c +1 -1
@@ -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))
Signature · 1 line
2.6.3
PATCH 4/5 block-LDM: Less function calls in ldm_validate_privheads() after error detection
In reply to SF Markus ElfringFrom: 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.
--- block/partitions/ldm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
block/partitions/ldm.c +18 -12
@@ -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, §);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; }
Signature · 1 line
2.6.3
PATCH 5/5 block-LDM: Fine-tuning for the source code formatting
In reply to SF Markus ElfringFrom: 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".
--- block/partitions/ldm.c | 405 ++++++++++++++++++++++++++----------------------- 1 file changed, 213 insertions(+), 192 deletions(-)
block/partitions/ldm.c +213 -192
@@ -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], §);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 , §);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 , §);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, §);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; }
Signature · 1 line
2.6.3
cover Documentation-getdelays: Fine-tuning for two functions
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- Documentation/accounting/getdelays.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
Documentation/accounting/getdelays.c +12 -9
@@ -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 ; }
Signature · 1 line
2.6.3
PATCH 2/3 Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()
In reply to SF Markus ElfringFrom: 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.
--- Documentation/accounting/getdelays.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/accounting/getdelays.c +2 -1
@@ -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" );
Signature · 1 line
2.6.3
PATCH 3/3 Documentation-getdelays: Less function calls in usage()
In reply to SF Markus ElfringFrom: 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.
--- Documentation/accounting/getdelays.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Documentation/accounting/getdelays.c +6 -6
@@ -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" ); }/*
Signature · 1 line
2.6.3
Jonathan Corbet
maintainerRe: [PATCH 1/3] Documentation-getdelays: Fix a check for container file usage in main()
In reply to SF Markus ElfringQuoted 7 lines · On Thu, 24 Dec 2015 13:34:20 +0100 SF Markus Elfring…
The
close()function could be called by themain()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
Jonathan Corbet
maintainerRe: [PATCH 2/3] Documentation-getdelays: Apply a recommendation from "checkpatch.pl" in main()
In reply to SF Markus ElfringQuoted 3 lines · On Thu, 24 Dec 2015 13:36:48 +0100 SF Markus Elfring…
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
Jonathan Corbet
maintainerRe: [PATCH 3/3] Documentation-getdelays: Less function calls in usage()
In reply to SF Markus ElfringQuoted 2 lines · On Thu, 24 Dec 2015 13:38:01 +0100 SF Markus Elfring…
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
Re: Documentation-getdelays: Fix a check for container file usage in main()
In reply to Jonathan CorbetQuoted 2 lines
Quoted 2 lines
The
close()function could be called by themain()function even if the passed variable "cfd" was assigned a negative value.
…
Quoted 1 line
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€c75a0f1d81922bf322c0634d1e1a15825a89e6#n425
Quoted 2 lines
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
--
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
Re: Documentation-getdelays: Less function calls in usage()
In reply to Jonathan CorbetQuoted 4 lines
Quoted 2 lines
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€c75a0f1d81922bf322c0634d1e1a15825a89e6#n4837
Regards,
Markus
--
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
ACPI-fan: Another source code review around null pointer handling?
In reply to SF Markus ElfringHello,
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€c75a0f1d81922bf322c0634d1e1a15825a89e6#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
--
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
sata_mv: Another source code review around exception handling?
In reply to SF Markus ElfringHello,
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€c75a0f1d81922bf322c0634d1e1a15825a89e6#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
--
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
PATCH 1/1 gpio-ucb1400: Delete an unnecessary variable initialisation in ucb1400_gpio_probe()
In reply to SF Markus ElfringFrom: 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.
--- drivers/gpio/gpio-ucb1400.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-ucb1400.c +1 -1
@@ -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 ;
Signature · 1 line
2.6.3
PATCH 1/1 i2c-core: One function call less in acpi_i2c_space_handler() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/i2c/i2c-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/i2c-core.c +5 -5
@@ -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; }
Signature · 1 line
2.6.3
kbuild test robot
build botRe: [PATCH] i2c-core: One function call less in acpi_i2c_space_handler() after error detection
reproduce:
[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
PATCH v2 1/1 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.
--- drivers/i2c/i2c-core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/i2c/i2c-core.c +6 -6
@@ -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; }
Signature · 1 line
2.6.3
Re: [PATCH v2] i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 3 lines
The
kfree()function was called in one case by theacpi_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.
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
Quoted 6 lines
Quoted 3 lines
The
kfree()function was called in one case by theacpi_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
cover IDE-ACPI: Fine-tuning for a function
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/ide/ide-acpi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/ide/ide-acpi.c +7 -6
@@ -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; }
Signature · 1 line
2.6.3
PATCH 2/3 IDE-ACPI: Delete unnecessary null pointer checks in ide_get_dev_handle()
In reply to SF Markus ElfringFrom: 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.
--- drivers/ide/ide-acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ide/ide-acpi.c +2 -2
@@ -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;
Signature · 1 line
2.6.3
PATCH 3/3 IDE-ACPI: Move an assignment for one variable in ide_get_dev_handle()
In reply to SF Markus ElfringFrom: 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.
--- drivers/ide/ide-acpi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/ide/ide-acpi.c +2 -3
@@ -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;
Signature · 1 line
2.6.3
PATCH 1/1 iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iio/adc/qcom-spmi-vadc.c +9 -8
@@ -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; }
Signature · 1 line
2.6.3
David Miller
maintainerRe: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
In reply to SF Markus ElfringIDE is in deep freeze maintainence mode.
Therefore patches that perform simplications and cleanups will not be accepted.
Thanks.
cover InfiniBand-ocrdma: Fine-tuning for some function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
Quoted 6 lines
Quoted 3 lines
The
kfree()function was called in one case by theacpi_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.
PATCH 1/6 InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()
In reply to SF Markus ElfringFrom: 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.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -6
@@ -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)
Signature · 1 line
2.6.3
PATCH 2/6 InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions
In reply to SF Markus ElfringFrom: 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.
--- 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(-)
drivers/infiniband/hw/ocrdma/ocrdma_ah.c +1 -1
@@ -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;
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +2 -2
@@ -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;
drivers/infiniband/hw/ocrdma/ocrdma_stats.c +2 -2
@@ -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;
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +6 -6
@@ -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);
Signature · 1 line
2.6.3
PATCH 3/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 18:28:35 +0100
Return zero at the end without using the local variable "status".
--- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_hw.c +1 -2
@@ -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)
Signature · 1 line
2.6.3
PATCH 4/6 InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly
In reply to SF Markus ElfringFrom: 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".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +1 -3
@@ -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,
Signature · 1 line
2.6.3
PATCH 5/6 InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq()
In reply to SF Markus ElfringFrom: 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".
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -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)
Signature · 1 line
2.6.3
PATCH 6/6 InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd()
In reply to SF Markus ElfringFrom: 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.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -4
@@ -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,
Signature · 1 line
2.6.3
Re: i2c-core: One function call less in acpi_i2c_space_handler() after error detection
In reply to Wolfram SangQuoted 4 lines
Quoted 2 lines
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.
Quoted 1 line
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.
Quoted 1 line
Also, this is not a hot path,
I'm curious if approaches around better exception handling can eventually become a "hot topic".
Quoted 1 line
so I see it as a micro-optimization
I can agree to this view for this function implementation.
Quoted 1 line
also adding complexity.
There are the usual software development trade-offs.
Quoted 1 line
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
kbuild test robot
build botRe: [PATCH 1/6] InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd()
In reply to SF Markus Elfringurl: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/InfiniBand-ocrdma-Fine-tuning-for-some-function-implementations/20151227-025304
[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]
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
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.
--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +3 -6
@@ -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)
Signature · 1 line
2.6.3
Joe Perches
maintainerRe: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
In reply to David MillerQuoted 4 lines · David Miller
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
Re: [PATCH 0/3] IDE-ACPI: Fine-tuning for a function
Quoted 6 lines · Joe Perches
Quoted 4 lines · David Miller
IDE is in deep freeze maintainence mode.
Therefore patches that perform simplications and cleanups will not be accepted.
Quoted 7 lines
Maybe there should be something like a README
indrivers/idethat says that.Maybe the
MAINTAINERSentry 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
cover InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/iser/iser_memory.c +2 -3
@@ -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,
Signature · 1 line
2.6.3
PATCH 2/2 InfiniBand-iSER-target: One jump label less in isert_reg_sig_mr()
In reply to SF Markus ElfringFrom: 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.
--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +3 -4
@@ -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
Signature · 1 line
2.6.3
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringQuoted 3 lines · SF Markus Elfring
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:
Quoted 19 lines
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 iniser_reg_sig_mr()
One jump label less inisert_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(-)Signature · 6 lines
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
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 27 Dec 2015 13:12:10 +0100
Subject: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementationsI 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 iniser_reg_sig_mr()
One jump label less inisert_reg_sig_mr()
Looks good,
Quoted 12 lines
drivers/infiniband/ulp/iser/iser_memory.c | 5 ++--- drivers/infiniband/ulp/isert/ib_isert.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)Signature · 6 lines
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
Re: [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations
In reply to SF Markus ElfringAlong with Leon's prefix comment:
PATCH 1/1 si2165: Refactoring for si2165_writereg_mask8()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/dvb-frontends/si2165.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/media/dvb-frontends/si2165.c +5 -9
@@ -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 }
Signature · 1 line
2.6.3
PATCH 1/1 bttv: Returning only value constants in two functions
In reply to SF Markus ElfringFrom: 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".
--- drivers/media/pci/bt8xx/bttv-driver.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/media/pci/bt8xx/bttv-driver.c +6 -19
@@ -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)
Signature · 1 line
2.6.3
PATCH 1/1 tuners: One check less in m88rs6000t_get_rf_strength() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/tuners/m88rs6000t.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/media/tuners/m88rs6000t.c +9 -7
@@ -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; }
Signature · 1 line
2.6.3
Re: [PATCH] [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 10:10:34 +0100This 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
Quoted 64 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/media/tuners/m88rs6000t.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)drivers/media/tuners/m88rs6000t.c +9
-8@@ -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
Re: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 5 lines
Quoted 3 lines
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.
Quoted 2 lines
and the enormous ugliness of a label inside an if by making two returns:
a return 0 for success and adev_dbgand 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
Re: [media] tuners: One check less in m88rs6000t_get_rf_strength() after error detection
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
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
Quoted 8 lines
I would find such a fine-tuning also nice in principle at more source code places.
Quoted 2 lines
and the enormous ugliness of a label inside an if by making two returns:
a return 0 for success and adev_dbgand 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
cover 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(-)
Signature · 1 line
2.6.3
PATCH 1/2 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".
--- drivers/media/tuners/m88rs6000t.c | 154 +++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 76 deletions(-)
drivers/media/tuners/m88rs6000t.c +78 -76
@@ -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; }
Signature · 1 line
2.6.3
Re: [PATCH 1/2] [media] m88rs6000t: Better exception handling in five functions
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 28 Dec 2015 15:10:30 +0100This 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
Quoted 390 lines
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(-)drivers/media/tuners/m88rs6000t.c +78
-77@@ -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
PATCH 2/2 tuners: Refactoring for m88rs6000t_sleep()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/tuners/m88rs6000t.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/tuners/m88rs6000t.c +5 -6
@@ -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)
Signature · 1 line
2.6.3
Re: [media] m88rs6000t: Better exception handling in five functions
In reply to Julia LawallQuoted 5 lines
Quoted 3 lines
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?
Quoted 1 line
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
Re: [media] m88rs6000t: Better exception handling in five functions
Quoted 7 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines
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.
Quoted 4 lines
Quoted 1 line
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
Re: sata_mv: Another source code review around exception handling?
In reply to SF Markus ElfringHello,
Quoted 3 lines · SF Markus Elfring
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.
Quoted 1 line
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.
Signature · 1 line
tejun
cover r820t: Fine-tuning for generic_set_freq()
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
PATCH 1/2 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.
--- drivers/media/tuners/r820t.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/tuners/r820t.c +1 -1
@@ -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",
Signature · 1 line
2.6.3
PATCH 2/2 r820t: Better exception handling in generic_set_freq()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/tuners/r820t.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/tuners/r820t.c +7 -9
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 xc5000: Faster result reporting in xc_load_fw_and_init_tuner()
In reply to SF Markus ElfringFrom: 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".
--- drivers/media/tuners/xc5000.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/tuners/xc5000.c +7 -9
@@ -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)
Signature · 1 line
2.6.3
PATCH 1/1 airspy: Better exception handling in two functions
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/usb/airspy/airspy.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/media/usb/airspy/airspy.c +10 -12
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 au0828: Refactoring for start_urb_transfer()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/usb/au0828/au0828-dvb.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/media/usb/au0828/au0828-dvb.c +5 -7
@@ -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)
Signature · 1 line
2.6.3
PATCH 1/1 hdpvr: Refactoring for hdpvr_read()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/usb/hdpvr/hdpvr-video.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/usb/hdpvr/hdpvr-video.c +2 -4
@@ -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 )
Signature · 1 line
2.6.3
PATCH 1/1 msi2500: Delete an unnecessary check in msi2500_set_usb_adc()
In reply to SF Markus ElfringFrom: 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.
--- drivers/media/usb/msi2500/msi2500.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/usb/msi2500/msi2500.c +0 -2
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 mfd-dm355evm_msp: One function call less in add_child() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/mfd/dm355evm_msp.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mfd/dm355evm_msp.c +10 -11
@@ -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)
Signature · 1 line
2.6.3
cover mfd: smsc-ece1099: Fine-tuning for smsc_i2c_probe()
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/mfd/smsc-ece1099.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/smsc-ece1099.c +1 -1
@@ -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 );
Signature · 1 line
2.6.3
PATCH 2/2 mfd: smsc-ece1099: Refactoring for smsc_i2c_probe()
In reply to SF Markus ElfringFrom: 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.
--- drivers/mfd/smsc-ece1099.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mfd/smsc-ece1099.c +3 -6
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 mfd: twl-core: One function call less in add_numbered_child() after error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/mfd/twl-core.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/mfd/twl-core.c +10 -11
@@ -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,
Signature · 1 line
2.6.3
PATCH 1/1 mmc-core: One check less in mmc_select_hs200() after error detection
In reply to SF Markus ElfringFrom: 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".
--- drivers/mmc/core/mmc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/mmc/core/mmc.c +5 -4
@@ -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; }
Signature · 1 line
2.6.3
cover mmc-host: Fine-tuning for one function
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/mmc/host/sdricoh_cs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/host/sdricoh_cs.c +3 -3
@@ -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
PATCH 2/2 mmc-sdricoh_cs: Less checks in sdricoh_init_mmc() after, error detection
In reply to SF Markus ElfringFrom: 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.
--- drivers/mmc/host/sdricoh_cs.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/sdricoh_cs.c +2 -2
@@ -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;
}
Signature · 1 line
2.6.3
cover mtd-rfd_ftl: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: 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(-)
Signature · 1 line
2.6.3
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.
--- drivers/mtd/rfd_ftl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mtd/rfd_ftl.c +7 -3
@@ -359,17 +359,21 @@ static int move_block_contents(struct partition *part, int block_no, u_long *oldvoid *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);
Signature · 1 line
2.6.3
PATCH 2/3 mtd-rfd_ftl: Refactoring for move_block_contents()
In reply to SF Markus ElfringFrom: 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.
--- drivers/mtd/rfd_ftl.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/mtd/rfd_ftl.c +8 -14
@@ -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; }
Signature · 1 line
2.6.3
PATCH 3/3 mtd-rfd_ftl: Refactoring for erase_block()
In reply to SF Markus ElfringFrom: 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.
--- drivers/mtd/rfd_ftl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/mtd/rfd_ftl.c +2 -4
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 net-thunder: One check less in nicvf_register_interrupts() after error detection
In reply to SF Markus ElfringFrom: 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".
--- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +7 -8
@@ -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; }
Signature · 1 line
2.6.3
PATCH 1/1 be2net: Delete an unnecessary check in two functions
In reply to SF Markus ElfringFrom: 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.
--- drivers/net/ethernet/emulex/benet/be_cmds.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/ethernet/emulex/benet/be_cmds.c +2 -7
@@ -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; }
Signature · 1 line
2.6.3
cover net-gianfar: Fine-tuning for gfar_ethflow_to_filer_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 13:15:34 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Less function calls after error detection
Delete unnecessary variable initialisations
Extend an initialisation clause of a for loop
drivers/net/ethernet/freescale/gianfar_ethtool.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 11:16:04 +0100
The kfree() function was called in one case by the gfar_ethflow_to_filer_table() function during error handling even if a passed variable contained a null pointer.
* Return directly if a memory allocation failed at the beginning.
* Adjust jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- drivers/net/ethernet/freescale/gianfar_ethtool.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +8 -6
@@ -778,11 +778,13 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, local_rqfpr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); +if (!local_rqfpr) +return 1 ; local_rqfcr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); -if (!local_rqfpr || !local_rqfcr) { +if (!local_rqfcr) { ret =0 ; - goto err; + goto free_fpr; }switch (class) {
@@ -802,7 +804,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"Right now this class is not supported\n" ); ret =0 ; - goto err; + goto free_fcr; }for (i =0 ; i <MAX_FILER_IDX +1 ; i++) {
@@ -819,7 +821,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"No parse rule found, can't create hash rules\n" ); ret =0 ; - goto err; + goto free_fcr; }/* If a match was found, then it begins the starting of a cluster rule
@@ -862,9 +864,9 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,break ; priv->cur_filer_idx = priv->cur_filer_idx -1 ; } - -err: +free_fcr:kfree (local_rqfcr); +free_fpr:kfree (local_rqfpr);return ret; }
Signature · 1 line
2.6.3
PATCH 2/3 net-gianfar: Delete unnecessary variable initialisations in gfar_ethflow_to_filer_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 12:56:23 +0100
Omit explicit initialisation at the beginning for four local variables which are redefined before their first use.
--- drivers/net/ethernet/freescale/gianfar_ethtool.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +3 -3
@@ -768,12 +768,12 @@ static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)static int gfar_ethflow_to_filer_table (struct gfar_private *priv,u64 ethflow,u64 class) { -unsigned int last_rule_idx = priv->cur_filer_idx; +unsigned int last_rule_idx;unsigned int cmp_rqfpr;unsigned int *local_rqfpr;unsigned int *local_rqfcr; -int i =0x0 , k =0x0 ; -int j =MAX_FILER_IDX , l =0x0 ; +int i, k, l; +int j =MAX_FILER_IDX ;int ret =1 ; local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
Signature · 1 line
2.6.3
PATCH 3/3 net-gianfar: Extend an initialisation clause of a for loop in gfar_ethflow_to_filer_table()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 13:00:06 +0100
Move the assignment for the variable "j" from the beginning into an initialisation clause of a for loop.
--- drivers/net/ethernet/freescale/gianfar_ethtool.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +2 -3
@@ -772,8 +772,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,unsigned int cmp_rqfpr;unsigned int *local_rqfpr;unsigned int *local_rqfcr; -int i, k, l; -int j =MAX_FILER_IDX ; +int i, j, k, l;int ret =1 ; local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
@@ -807,7 +806,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, goto free_fcr; } -for (i =0 ; i <MAX_FILER_IDX +1 ; i++) { +for (i =0 , j =MAX_FILER_IDX ; i <MAX_FILER_IDX +1 ; i++) { local_rqfpr[j] = priv->ftp_rqfpr[i]; local_rqfcr[j] = priv->ftp_rqfcr[i]; j--;
Signature · 1 line
2.6.3
Re: [PATCH 1/3] net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
In reply to SF Markus ElfringQuoted 23 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 11:16:04 +0100The
kfree()function was called in one case by thegfar_ethflow_to_filer_table()function during error handling even if a passed variable contained a null pointer.* Return directly if a memory allocation failed at the beginning.
* Adjust 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/net/ethernet/freescale/gianfar_ethtool.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/net/ethernet/freescale/gianfar_ethtool.c +0
-0
drivers/net/ethernet/freescale/gianfar_ethtool.c static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, · line 782
Quoted 5 lines
drivers/net/ethernet/freescale/gianfar_ethtool.c +2
-0@@ -778,11 +778,13 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, local_rqfpr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); +if (!local_rqfpr) +return 1 ;
Why return 1? Previously 0 was returned.
Normally, one returns -ENOMEM for this case, but it looks like this function is returning 0 on failure.
julia
Quoted 48 lines
drivers/net/ethernet/freescale/gianfar_ethtool.c +6
-6local_rqfcr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); -if (!local_rqfpr || !local_rqfcr) { +if (!local_rqfcr) { ret =0 ; - goto err; + goto free_fpr; }switch (class) {@@ -802,7 +804,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"Right now this class is not supported\n" ); ret =0 ; - goto err; + goto free_fcr; }for (i =0 ; i <MAX_FILER_IDX +1 ; i++) {@@ -819,7 +821,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"No parse rule found, can't create hash rules\n" ); ret =0 ; - goto err; + goto free_fcr; }/* If a match was found, then it begins the starting of a cluster rule @@ -862,9 +864,9 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,break ; priv->cur_filer_idx = priv->cur_filer_idx -1 ; } - -err: +free_fcr:kfree (local_rqfcr); +free_fpr:kfree (local_rqfpr);return ret; }Signature · 6 lines
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
Re: [PATCH 1/3] net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
Quoted 9 lines
drivers/net/ethernet/freescale/gianfar_ethtool.c static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, · line 782
Quoted 7 lines
+++
b/drivers/net/ethernet/freescale/gianfar_ethtool.cdrivers/net/ethernet/freescale/gianfar_ethtool.c +2
-0@@ -778,11 +778,13 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, local_rqfpr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); +if (!local_rqfpr) +return 1 ;Why return 1? Previously 0 was returned.
You are right. - Unfortunately, I made a mistake at this place of my update suggestion.
Quoted 2 lines
Normally, one returns
-ENOMEMfor this case, but it looks like this function is returning 0 on failure.
Should a symbol like "false" be used instead of such a special number?
Regards,
Markus
PATCH v2 1/3 net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
In reply to Julia LawallFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 13:56:09 +0100
The kfree() function was called in one case by the gfar_ethflow_to_filer_table() function during error handling even if a passed variable contained a null pointer.
* Return directly if a memory allocation failed at the beginning.
* Adjust jump targets according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- drivers/net/ethernet/freescale/gianfar_ethtool.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +8 -6
@@ -778,11 +778,13 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, local_rqfpr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); +if (!local_rqfpr) +return 0 ; local_rqfcr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); -if (!local_rqfpr || !local_rqfcr) { +if (!local_rqfcr) { ret =0 ; - goto err; + goto free_fpr; }switch (class) {
@@ -802,7 +804,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"Right now this class is not supported\n" ); ret =0 ; - goto err; + goto free_fcr; }for (i =0 ; i <MAX_FILER_IDX +1 ; i++) {
@@ -819,7 +821,7 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,netdev_err (priv->ndev,"No parse rule found, can't create hash rules\n" ); ret =0 ; - goto err; + goto free_fcr; }/* If a match was found, then it begins the starting of a cluster rule
@@ -862,9 +864,9 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,break ; priv->cur_filer_idx = priv->cur_filer_idx -1 ; } - -err: +free_fcr:kfree (local_rqfcr); +free_fpr:kfree (local_rqfpr);return ret; }
Signature · 1 line
2.6.3
Re: [PATCH 1/3] net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
Quoted 9 lines
drivers/net/ethernet/freescale/gianfar_ethtool.c static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, · line 782
Quoted 7 lines
+++
b/drivers/net/ethernet/freescale/gianfar_ethtool.cdrivers/net/ethernet/freescale/gianfar_ethtool.c +2
-0@@ -778,11 +778,13 @@ static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, local_rqfpr =kmalloc_array (MAX_FILER_IDX +1 ,sizeof (unsigned int ),GFP_KERNEL ); +if (!local_rqfpr) +return 1 ;Why return 1? Previously 0 was returned.
Quoted 8 lines
You are right. - Unfortunately, I made a mistake at this place of my update suggestion.
Quoted 2 lines
Normally, one returns
-ENOMEMfor this case, but it looks like this function is returning 0 on failure.Should a symbol like "false" be used instead of such a special number?
Maybe it's better than 0 and 1...
julia
PATCH 1/1 net-i40e: Replace variable initialisations by assignments in i40e_vc_get_vf_resources_msg()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 15:11:09 +0100
Replace explicit initialisations for four local variables at the beginning by assignments that will only be performed if the corresponding code will really be executed.
--- drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +9 -6
@@ -1172,16 +1172,18 @@ static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)**/ static int i40e_vc_get_vf_resources_msg (struct i40e_vf *vf,u8 *msg) { -struct i40e_virtchnl_vf_resource *vfres =NULL ; -struct i40e_pf *pf = vf->pf; -i40e_status aq_ret =0 ; +struct i40e_virtchnl_vf_resource *vfres; +struct i40e_pf *pf; +i40e_status aq_ret;struct i40e_vsi *vsi; -int i =0 , len =0 ; +int i =0 ;int num_vsis =1 ; -int ret; +int len, ret;if (!test_bit (I40E_VF_STAT_INIT , &vf->vf_states)) { aq_ret =I40E_ERR_PARAM ; + vfres =NULL ; + len =0 ; goto err; }
@@ -1202,6 +1204,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)I40E_VIRTCHNL_VF_OFFLOAD_VLAN ; vfres->vf_offload_flags =I40E_VIRTCHNL_VF_OFFLOAD_L2 ; + pf = vf->pf; vsi = pf->vsi[vf->lan_vsi_idx];if (!vsi->info.pvid) vfres->vf_offload_flags |=I40E_VIRTCHNL_VF_OFFLOAD_VLAN ;
@@ -1231,7 +1234,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg) i++; }set_bit (I40E_VF_STAT_ACTIVE , &vf->vf_states); - + aq_ret =0 ; err:/* send the response back to the VF */ ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
Signature · 1 line
2.6.3
Re: [PATCH 1/3] net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
In reply to Julia LawallJulia Lawall <[email protected]> :
Quoted 1 line · SF Markus Elfring
[...]
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Normally, one returns
-ENOMEMfor this case, but it looks like this function is returning 0 on failure.Should a symbol like "false" be used instead of such a special number?
Maybe it's better than 0 and 1...
Your suggestion about -ENOMEM is consistent with the callchain. Nothing else is needed.
Btw:
1. kfree does not care about NULL parameter, especially in this hardly timing sensitive path.
2. kmalloc_array for small kernel controlled arrays of integers (see drivers/net/ethernet/freescale/gianfar.h), seriously ?
I'd suggest the janitor to introduce a dedicated struct to embed both gfar_private.ftp_rqf{p, c}r then use a single, plain kmalloc in gfar_ethflow_to_filer_table.
Happy tasteful 2016 :o)
Signature · 1 line
Ueimor
net-i40e: Reconsider further usage of variable "i" in i40e_vc_get_vf_resources_msg()
In reply to SF Markus ElfringHello,
I have taken another look at the implementation of the
function "i40e_vc_get_vf_resources_msg". I find the use of the variable "i" strange there. It seems that the value from the increment operation in an if branch is not reused so far.
I would appreciate a further clarification.
Can this variable be eventually deleted?
Regards,
Markus
PATCH 1/1 net-huawei_cdc_ncm: Delete an unnecessary variable initialisation in huawei_cdc_ncm_bind()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 16:54:13 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/usb/huawei_cdc_ncm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/huawei_cdc_ncm.c +1 -1
@@ -71,7 +71,7 @@ static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev, {struct cdc_ncm_ctx *ctx;struct usb_driver *subdriver =ERR_PTR (-ENODEV ); -int ret = -ENODEV ; +int ret;struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;int drvflags =0 ;
Signature · 1 line
2.6.3
cover net-qmi_wwan: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 17:47:46 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Refactoring for qmi_wwan_bind()
Delete an unnecessary variable initialisation in qmi_wwan_register_subdriver()
drivers/net/usb/qmi_wwan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 net-qmi_wwan: Refactoring for qmi_wwan_bind()
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 17:32:07 +0100
Reduce the scope for the local variable "desc" to one branch of an if statement.
--- drivers/net/usb/qmi_wwan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/usb/qmi_wwan.c +2 -1
@@ -345,7 +345,6 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)int status =-1 ;u8 *buf = intf->cur_altsetting->extra;int len = intf->cur_altsetting->extralen; -struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc;struct usb_cdc_union_desc *cdc_union;struct usb_cdc_ether_desc *cdc_ether;struct usb_driver *driver =driver_of (intf);
@@ -366,6 +365,8 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)/* Use separate control and data interfaces if we found a CDC Union */ if (cdc_union) { +struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc; + info->data =usb_ifnum_to_if (dev->udev, cdc_union->bSlaveInterface0); if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 ||
Signature · 1 line
2.6.3
PATCH 2/2 net-qmi_wwan: Delete an unnecessary variable initialisation in qmi_wwan_register_subdriver()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 17:35:03 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/usb/qmi_wwan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/qmi_wwan.c +1 -1
@@ -286,7 +286,7 @@ static int qmi_wwan_cdc_wdm_manage_power(struct usb_interface *intf, int on)static int qmi_wwan_register_subdriver (struct usbnet *dev) {int rv; -struct usb_driver *subdriver =NULL ; +struct usb_driver *subdriver;struct qmi_wwan_state *info = (void *)&dev->data;/* collect bulk endpoints */
Signature · 1 line
2.6.3
cover net-ath9k_htc: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 19:16:05 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an unnecessary variable initialisation in ath9k_hif_usb_rx_stream() Replace a variable initialisation by an assignment in ath9k_htc_set_channel()
drivers/net/wireless/ath/ath9k/hif_usb.c | 2 +- drivers/net/wireless/ath/ath9k/htc_drv_main.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/2 net-ath9k_htc: Delete an unnecessary variable initialisation in ath9k_hif_usb_rx_stream()
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 19:00:53 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/wireless/ath/ath9k/hif_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/hif_usb.c +1 -1
@@ -525,7 +525,7 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, struct sk_buff *skb) {struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER ]; -int index =0 , i =0 , len = skb->len; +int index =0 , i, len = skb->len;int rx_remain_len, rx_pkt_len;u16 pool_index =0 ;u8 *ptr;
Signature · 1 line
2.6.3
PATCH 2/2 net-ath9k_htc: Replace a variable initialisation by an assignment in ath9k_htc_set_channel()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 19:09:32 +0100
Replace an explicit initialisation for one local variable at the beginning by a conditional assignment.
--- drivers/net/wireless/ath/ath9k/htc_drv_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/wireless/ath/ath9k/htc_drv_main.c +2 -5
@@ -246,7 +246,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,struct ieee80211_conf *conf = &common->hw->conf;bool fastcc;struct ieee80211_channel *channel = hw->conf.chandef.chan; -struct ath9k_hw_cal_data *caldata =NULL ; +struct ath9k_hw_cal_data *caldata;enum htc_phymode mode;__be16 htc_mode;u8 cmd_rsp;
@@ -274,10 +274,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, priv->ah->curchan->channel, channel->center_freq,conf_is_ht (conf),conf_is_ht40 (conf), fastcc); - -if (!fastcc) - caldata = &priv->caldata; - + caldata = fastcc ?NULL : &priv->caldata; ret =ath9k_hw_reset (ah, hchan, caldata, fastcc);if (ret) { ath_err(common,
Signature · 1 line
2.6.3
Re: [PATCH 2/2] net-ath9k_htc: Replace a variable initialisation by an assignment in ath9k_htc_set_channel()
Am 01.01.2016 um 19:25 schrieb SF Markus Elfring:
Quoted 27 lines
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 19:09:32 +0100Replace an explicit initialisation for one local variable at the beginning by a conditional assignment.
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/ath/ath9k/htc_drv_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/net/wireless/ath/ath9k/htc_drv_main.c +1
-1@@ -246,7 +246,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,struct ieee80211_conf *conf = &common->hw->conf;bool fastcc;struct ieee80211_channel *channel = hw->conf.chandef.chan; -struct ath9k_hw_cal_data *caldata =NULL ; +struct ath9k_hw_cal_data *caldata;enum htc_phymode mode;__be16 htc_mode;u8 cmd_rsp;@@ -274,10 +274,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, priv->ah->curchan->channel,
drivers/net/wireless/ath/ath9k/htc_drv_main.c static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, · line 280
Quoted 10 lines
drivers/net/wireless/ath/ath9k/htc_drv_main.c +1
-4channel->center_freq,conf_is_ht (conf),conf_is_ht40 (conf), fastcc); - -if (!fastcc) - caldata = &priv->caldata; - + caldata = fastcc ?NULL : &priv->caldata; ret =ath9k_hw_reset (ah, hchan, caldata, fastcc);if (ret) { ath_err(common,
Signature · 10 lines
Regards, Oleksij -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 213 bytes Desc: OpenPGP digital signature Url : http://lists.ath9k.org/pipermail/ath9k-devel/attachments/20160101/a7f6d86e/attachment.pgp
Re: [PATCH 1/2] net-ath9k_htc: Delete an unnecessary variable initialisation in ath9k_hif_usb_rx_stream()
In reply to SF Markus ElfringAm 01.01.2016 um 19:23 schrieb SF Markus Elfring:
Quoted 17 lines
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 19:00:53 +0100Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/ath/ath9k/hif_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/ath/ath9k/hif_usb.c +0
-0
drivers/net/wireless/ath/ath9k/hif_usb.c static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, · line 531
Quoted 8 lines
drivers/net/wireless/ath/ath9k/hif_usb.c +1
-1@@ -525,7 +525,7 @@ static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, struct sk_buff *skb) {struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER ]; -int index =0 , i =0 , len = skb->len; +int index =0 , i, len = skb->len;int rx_remain_len, rx_pkt_len;u16 pool_index =0 ;u8 *ptr;
Signature · 10 lines
Regards, Oleksij -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 213 bytes Desc: OpenPGP digital signature Url : http://lists.ath9k.org/pipermail/ath9k-devel/attachments/20160101/9f7764b8/attachment.pgp
PATCH 1/1 net-brcmfmac: Delete an unnecessary variable initialisation in brcmf_sdio_download_firmware()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 20:20:15 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +1 -1
@@ -3260,7 +3260,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,const struct firmware *fw, void *nvram, u32 nvlen) { - int bcmerror = -EFAULT; + int bcmerror;u32 rstvec;sdio_claim_host (bus->sdiodev->func[1 ]);
Signature · 1 line
2.6.3
cover net-iwlegacy: Fine-tuning for il_eeprom_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 21:25:43 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Refactoring
One check less after error detection
Another refactoring
drivers/net/wireless/intel/iwlegacy/common.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 net-iwlegacy: Refactoring for il_eeprom_init()
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 20:54:25 +0100
Return directly if a memory allocation failed at the beginning.
--- drivers/net/wireless/intel/iwlegacy/common.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/wireless/intel/iwlegacy/common.c +3 -5
@@ -723,10 +723,9 @@ il_eeprom_init(struct il_priv *il) sz = il->cfg->eeprom_size;D_EEPROM ("NVM size = %d\n" , sz); il->eeprom =kzalloc (sz,GFP_KERNEL ); -if (!il->eeprom) { - ret = -ENOMEM ; - goto alloc_err; - } +if (!il->eeprom) +return -ENOMEM ; + e = (__le16 *) il->eeprom; il->ops->apm_init (il);
@@ -778,7 +777,6 @@ err:il_eeprom_free (il);/* Reset chip to save power until we load uCode during "up". */ il_apm_stop (il); -alloc_err:return ret; }EXPORT_SYMBOL (il_eeprom_init);
Signature · 1 line
2.6.3
PATCH 2/3 net-iwlegacy: One check less in il_eeprom_init() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 21:12:29 +0100
This issue was detected by using the Coccinelle software.
Adjust a jump target to avoid a check repetition before the function call "il_eeprom_free".
--- drivers/net/wireless/intel/iwlegacy/common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/intel/iwlegacy/common.c +6 -4
@@ -734,7 +734,7 @@ il_eeprom_init(struct il_priv *il)if (ret <0 ) {IL_ERR ("EEPROM not found, EEPROM_GP=0x%08x\n" , gp); ret = -ENOENT ; - goto err; + goto free_eeprom; }/* Make sure driver (instead of uCode) is allowed to read EEPROM */
@@ -742,7 +742,7 @@ il_eeprom_init(struct il_priv *il)if (ret <0 ) {IL_ERR ("Failed to acquire EEPROM semaphore.\n" ); ret = -ENOENT ; - goto err; + goto free_eeprom; }/* eeprom is an array of 16bit values */
@@ -772,9 +772,11 @@ il_eeprom_init(struct il_priv *il) done: il->ops->eeprom_release_semaphore (il); -err: -if (ret) +if (ret) { +free_eeprom:il_eeprom_free (il); + } +/* Reset chip to save power until we load uCode during "up". */ il_apm_stop (il);return ret;
Signature · 1 line
2.6.3
PATCH 3/3 net-iwlegacy: Another refactoring for il_eeprom_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 21:16:01 +0100
Rename a jump label according to the current Linux coding style convention.
--- drivers/net/wireless/intel/iwlegacy/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlegacy/common.c +2 -2
@@ -759,7 +759,7 @@ il_eeprom_init(struct il_priv *il) IL_EEPROM_ACCESS_TIMEOUT);if (ret <0 ) {IL_ERR ("Time out reading EEPROM[%d]\n" , addr); - goto done; + goto release_semaphore; } r =_il_rd (il,CSR_EEPROM_REG ); e[addr /2 ] =cpu_to_le16 (r >>16 );
@@ -769,7 +769,7 @@ il_eeprom_init(struct il_priv *il) il_eeprom_query16(il, EEPROM_VERSION)); ret =0 ; -done: +release_semaphore: il->ops->eeprom_release_semaphore (il);if (ret) {
Signature · 1 line
2.6.3
PATCH 1/1 net-libertas: Better exception handling in if_spi_host_to_card_worker()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 22:27:20 +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 function call failed. Use the identifier "report_failure" instead of the label "err".
--- drivers/net/wireless/marvell/libertas/if_spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/wireless/marvell/libertas/if_spi.c +6 -5
@@ -880,18 +880,18 @@ static void if_spi_host_to_card_worker(struct work_struct *work) &hiStatus);if (err) {netdev_err (priv->dev,"I/O error\n" ); - goto err; + goto report_failure; }if (hiStatus &IF_SPI_HIST_CMD_UPLOAD_RDY ) { err =if_spi_c2h_cmd (card);if (err) - goto err; + goto report_failure; }if (hiStatus &IF_SPI_HIST_RX_UPLOAD_RDY ) { err =if_spi_c2h_data (card);if (err) - goto err; + goto report_failure; }/*
@@ -940,9 +940,10 @@ static void if_spi_host_to_card_worker(struct work_struct *work)if (hiStatus &IF_SPI_HIST_CARD_EVENT )if_spi_e2h (card); -err: -if (err) +if (err) { +report_failure:netdev_err (priv->dev,"%s: got error %d\n" , __func__, err); + }lbs_deb_leave (LBS_DEB_SPI ); }
Signature · 1 line
2.6.3
Re: [PATCH] net-libertas: Better exception handling in if_spi_host_to_card_worker()
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 22:27:20 +0100This 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 function call failed.
Putting a label inside an if is ugly.
julia
Quoted 54 lines
Use the identifier "
report_failure" instead of the label "err".Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/marvell/libertas/if_spi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/net/wireless/marvell/libertas/if_spi.c +6
-5@@ -880,18 +880,18 @@ static void if_spi_host_to_card_worker(struct work_struct *work) &hiStatus);if (err) {netdev_err (priv->dev,"I/O error\n" ); - goto err; + goto report_failure; }if (hiStatus &IF_SPI_HIST_CMD_UPLOAD_RDY ) { err =if_spi_c2h_cmd (card);if (err) - goto err; + goto report_failure; }if (hiStatus &IF_SPI_HIST_RX_UPLOAD_RDY ) { err =if_spi_c2h_data (card);if (err) - goto err; + goto report_failure; }/* @@ -940,9 +940,10 @@ static void if_spi_host_to_card_worker(struct work_struct *work)if (hiStatus &IF_SPI_HIST_CARD_EVENT )if_spi_e2h (card); -err: -if (err) +if (err) { +report_failure:netdev_err (priv->dev,"%s: got error %d\n" , __func__, err); + }lbs_deb_leave (LBS_DEB_SPI ); }Signature · 6 lines
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
Re: [PATCH 2/3] net-iwlegacy: One check less in il_eeprom_init() after error detection
In reply to SF Markus ElfringHello.
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 21:12:29 +0100This issue was detected by using the Coccinelle software.
Adjust a jump target to avoid a check repetition before the function call "
il_eeprom_free".
One question: why?
Quoted 10 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/intel/iwlegacy/common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/net/wireless/intel/iwlegacy/common.c +0
-0
[...]
drivers/net/wireless/intel/iwlegacy/common.c il_eeprom_init(struct il_priv *il) · line 776
Quoted 8 lines
drivers/net/wireless/intel/iwlegacy/common.c +2
-2@@ -772,9 +772,11 @@ il_eeprom_init(struct il_priv *il) done: il->ops->eeprom_release_semaphore (il); -err: -if (ret) +if (ret) { +free_eeprom:
This is ugly, I'd say.
[...]
MBR, Sergei
Re: [PATCH] net-libertas: Better exception handling in if_spi_host_to_card_worker()
In reply to SF Markus ElfringHello
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 22:27:20 +0100This 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 function call failed. Use the identifier "
report_failure" instead of the label "err".
Why? The code was smart enough and you're making it uglier that it needs
to be.
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>
MBR, Sergei
David Miller
maintainerRe: [PATCH v2 1/3] net-gianfar: Less function calls in gfar_ethflow_to_filer_table() after error detection
In reply to SF Markus ElfringThis is not the proper way to resubmit patches when you are asked to make changes to some portion of a multi-patch series.
You must always resubmit the entire series when this happens, not just the patch that changes.
And in the revised cover "0/N" posting you list the revisions that were made.
Re: [PATCH] net-libertas: Better exception handling in if_spi_host_to_card_worker()
In reply to Sergei ShtylyovQuoted 6 lines
Quoted 4 lines
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 function call failed. Use the identifier "
report_failure" instead of the label "err".Why?
I suggest to reconsider the places with which such a jump label is connected.
Quoted 1 line
The code was smart enough
Which action should really be performed after a failure was detected and handled a bit already?
* Another condition check
* Just additional error logging
Quoted 1 line
and you're making it uglier that it needs to be.
I assume that a software development taste can evolve, can't it?
Regards,
Markus
Re: [PATCH] net-libertas: Better exception handling in if_spi_host_to_card_worker()
Quoted 16 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
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 function call failed. Use the identifier "
report_failure" instead of the label "err".Why?
I suggest to reconsider the places with which such a jump label is connected.
Quoted 1 line
The code was smart enough
Which action should really be performed after a failure was detected and handled a bit already?
Quoted 8 lines
* Another condition check
* Just additional error logging
Quoted 1 line
and you're making it uglier that it needs to be.
I assume that a software development taste can evolve, can't it?
So far, you have gotten several down votes for this kind of change, and no enthusiasm.
Admittedly, this is a trivial case, because there are no local variables, but do you actually know the semantics in C of a jump into a block? And if you do know, do you think that this semantics is common knowledge? And do you really think that introducing poorly understandable code is really worth saving an if test of a single variable on a non-critical path?
Most of the kernel code is not performance critical at the level of a single if test. So the goal should be for the code to be easy to understand and robust to change. The code that is performance critical, you should probably not touch, ever. The people who wrote it knew what was important and what was not.
julia
Re: [PATCH] net-brcmfmac: Delete an unnecessary variable initialisation in brcmf_sdio_download_firmware()
In reply to SF Markus ElfringQuoted 2 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 20:20:15 +0100
I think it has been said over and over, but please use driver name only as prefix. I don't see value to prepend it with 'net-'.
Quoted 3 lines
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
That being said here is my....
Quoted 19 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +1
-1@@ -3260,7 +3260,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,const struct firmware *fw, void *nvram, u32 nvlen) { - int bcmerror = -EFAULT; + int bcmerror;u32 rstvec;sdio_claim_host (bus->sdiodev->func[1 ]);
Re: net-libertas: Better exception handling in if_spi_host_to_card_worker()
In reply to Julia LawallQuoted 3 lines
Quoted 1 line
I assume that a software development taste can evolve, can't it?
So far, you have gotten several down votes for this kind of change,
I am curious when more contributors will share corresponding opinions.
Quoted 1 line
and no enthusiasm.
How many software designers and developers can become enthusiastic about better exception handling to some degree?
Quoted 1 line
The code that is performance critical, you should probably not touch, ever.
I imagine that technical evolution will result in further considerations so that "unchangeable" components can be adjusted once more.
Quoted 1 line
The people who wrote it knew what was important and what was not.
I might come along at some places where the affected knowledge will also evolve.
Regards,
Markus
Re: net-libertas: Better exception handling in if_spi_host_to_card_worker()
Quoted 5 lines · SF Markus Elfring
Quoted 3 lines
Quoted 1 line
I assume that a software development taste can evolve, can't it?
So far, you have gotten several down votes for this kind of change,
I am curious when more contributors will share corresponding opinions.
Let's burn some cycles on this while the holidays give me time to do so. "software development taste" is another term for "coding style". In every project battles are fought over this between friends and foes. I have never seen much evolution going on in this area.
Quoted 4 lines
Quoted 1 line
and no enthusiasm.
How many software designers and developers can become enthusiastic about better exception handling to some degree?
I had to take a look at this particular patch and I have to say that I don't see, using your favorite term, evolution at work. It looks more like the result of inbred. What the patch tries to do is avoid the extra 'if (err)'. Setting coding style aside, the question is whether there is a good metric for the patch. So does it really safe processing time? Did you look at the resulting assembly code for different target architectures?
You got pushed back on the change so you have to come up with solid arguments for your change instead of spewing ideas about evolution in software development. Running Coccinelle is one thing, but understanding the results and what you are ultimately proposing to be changed is more important.
Regards,
Arend
Quoted 17 lines
Quoted 1 line
The code that is performance critical, you should probably not touch, ever.
I imagine that technical evolution will result in further considerations so that "unchangeable" components can be adjusted once more.
Quoted 1 line
The people who wrote it knew what was important and what was not.
I might come along at some places where the affected knowledge will also evolve.
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: net-libertas: Better exception handling in if_spi_host_to_card_worker()
Quoted 1 line
I have never seen much evolution going on in this area.
I can get an other impression from a specific document for example.
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/Documentation/CodingStyle
Quoted 1 line
What the patch tries to do is avoid the extra 'if (err)'.
Yes. - I propose to look at related consequences together with the usage of a popular short jump label once more.
Quoted 2 lines
Setting coding style aside, the question is whether there is a good metric for the patch.
A software development challenge is to accept changes also around a topic like "error handling". My update suggestion for the source file "drivers/net/wireless/marvell/libertas/if_spi.c" should only improve exception handling. (I came along other source files where more improvements will eventually be possible.)
When will the run-time behaviour matter also for exceptional situations?
Quoted 1 line
Did you look at the resulting assembly code for different target architectures?
Not yet. - Which execution system variants would you recommend for further comparisons?
Regards,
Markus
cover net-rsi: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 15:36:25 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete unnecessary variable initialisations in rsi_send_mgmt_pkt() Delete unnecessary variable initialisations in rsi_send_data_pkt() Replace variable initialisations by assignments in rsi_send_data_pkt()
drivers/net/wireless/rsi/rsi_91x_pkt.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 rsi: Delete unnecessary variable initialisations in rsi_send_mgmt_pkt()
From: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 14:54:30 +0100
Omit explicit initialisation at the beginning for five local variables which are redefined before their first use.
--- drivers/net/wireless/rsi/rsi_91x_pkt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/wireless/rsi/rsi_91x_pkt.c +5 -5
@@ -123,15 +123,15 @@ int rsi_send_mgmt_pkt(struct rsi_common *common, struct sk_buff *skb) {struct rsi_hw *adapter = common->priv; -struct ieee80211_hdr *wh =NULL ; +struct ieee80211_hdr *wh;struct ieee80211_tx_info *info; -struct ieee80211_bss_conf *bss =NULL ; +struct ieee80211_bss_conf *bss;struct ieee80211_hw *hw = adapter->hw;struct ieee80211_conf *conf = &hw->conf;struct skb_info *tx_params; -int status = -E2BIG ; -__le16 *msg =NULL ; -u8 extnd_size =0 ; +int status; +__le16 *msg; +u8 extnd_size;u8 vap_id =0 ; info =IEEE80211_SKB_CB (skb);
Signature · 1 line
2.6.3
PATCH 2/3 rsi: Delete unnecessary variable initialisations in rsi_send_data_pkt()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 15:15:12 +0100
Omit explicit initialisation at the beginning for four local variables which are redefined before their first use.
--- drivers/net/wireless/rsi/rsi_91x_pkt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/rsi/rsi_91x_pkt.c +4 -4
@@ -27,15 +27,15 @@int rsi_send_data_pkt (struct rsi_common *common,struct sk_buff *skb) {struct rsi_hw *adapter = common->priv; -struct ieee80211_hdr *tmp_hdr =NULL ; +struct ieee80211_hdr *tmp_hdr;struct ieee80211_tx_info *info;struct skb_info *tx_params; -struct ieee80211_bss_conf *bss =NULL ; +struct ieee80211_bss_conf *bss;int status = -EINVAL ;u8 ieee80211_size =MIN_802_11_HDR_LEN ; -u8 extnd_size =0 ; +u8 extnd_size;__le16 *frame_desc; -u16 seq_num =0 ; +u16 seq_num; info =IEEE80211_SKB_CB (skb); bss = &info->control.vif->bss_conf;
Signature · 1 line
2.6.3
PATCH 3/3 rsi: Replace variable initialisations by assignments in rsi_send_data_pkt()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 15:25:34 +0100
Replace explicit initialisation for two local variables at the beginning by assignments.
--- drivers/net/wireless/rsi/rsi_91x_pkt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/rsi/rsi_91x_pkt.c +6 -4
@@ -26,12 +26,12 @@*/ int rsi_send_data_pkt (struct rsi_common *common,struct sk_buff *skb) { -struct rsi_hw *adapter = common->priv; +struct rsi_hw *adapter;struct ieee80211_hdr *tmp_hdr;struct ieee80211_tx_info *info;struct skb_info *tx_params;struct ieee80211_bss_conf *bss; -int status = -EINVAL ; +int status;u8 ieee80211_size =MIN_802_11_HDR_LEN ;u8 extnd_size;__le16 *frame_desc;
@@ -41,8 +41,10 @@ int rsi_send_data_pkt(struct rsi_common *common, struct sk_buff *skb) bss = &info->control.vif->bss_conf; tx_params = (struct skb_info *)info->driver_data; -if (!bss->assoc) +if (!bss->assoc) { + status = -EINVAL ; goto err; + } tmp_hdr = (struct ieee80211_hdr *)&skb->data[0 ]; seq_num = (le16_to_cpu (tmp_hdr->seq_ctrl) >>4 );
@@ -97,7 +99,7 @@ int rsi_send_data_pkt(struct rsi_common *common, struct sk_buff *skb) frame_desc[7 ] =cpu_to_le16 (((tx_params->tid &0xf ) <<4 ) | (skb->priority &0xf ) | (tx_params->sta_id <<8 )); - + adapter = common->priv; status = adapter->host_intf_write_pkt (common->priv, skb->data, skb->len);
Signature · 1 line
2.6.3
Re: [PATCH 3/3] rsi: Replace variable initialisations by assignments in rsi_send_data_pkt()
SF Markus Elfring <[email protected]> :
Quoted 5 lines
From: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 15:25:34 +0100Replace explicit initialisation for two local variables at the beginning by assignments.
It makes no sense for the 'adapter' variable.
Signature · 1 line
Ueimor
net-rsi: Reconsider usage of variable "vap_id" in rsi_send_mgmt_pkt()
In reply to SF Markus ElfringHello,
I have taken another look at the implementation of the function "rsi_send_mgmt_pkt".
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/net/wireless/rsi/rsi_91x_pkt.c?idèc58e7a5a106c3d557fccd01cd4d1128f9bab38#n114
I find the following statement combination interesting there.
…
u8 vap_id = 0; … msg[7] |= cpu_to_le16(vap_id << 8);
…
I would appreciate a further clarification.
Does a shift operation for a variable which contains zero indicate an open issue?
Regards,
Markus
--
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
kbuild test robot
build botRe: [PATCH 1/3] rsi: Delete unnecessary variable initialisations in rsi_send_mgmt_pkt()
In reply to SF Markus Elfringreproduce:
Hi Markus,
[auto build test WARNING on wireless-drivers-next/master]
[also build test WARNING on v4.4-rc7 next-20151231]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/net-rsi-Fine-tuning-for-two-function-implementations/20160102-224740 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master config: x86_64-randconfig-s2-01030012 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
All warnings (new ones prefixed by >>):
drivers/net/wireless/rsi/rsi_91x_pkt.c: In function 'rsi_send_mgmt_pkt':
>> drivers/net/wireless/rsi/rsi_91x_pkt.c:211:2: warning: 'status' may be used uninitialized in this function [-Wmaybe-uninitialized]
rsi_indicate_tx_status(common->priv, skb, status);
^vim +/status +211 drivers/net/wireless/rsi/rsi_91x_pkt.c
dad0d04f Fariya Fatima 2014-03-16 195 /* Indicate to firmware to give cfm */
dad0d04f Fariya Fatima 2014-03-16 196 if ((skb->data[16] == IEEE80211_STYPE_PROBE_REQ) && (!bss->assoc)) {
dad0d04f Fariya Fatima 2014-03-16 197 msg[1] |= cpu_to_le16(BIT(10));
dad0d04f Fariya Fatima 2014-03-16 198 msg[7] = cpu_to_le16(PROBEREQ_CONFIRM);
dad0d04f Fariya Fatima 2014-03-16 199 common->mgmt_q_block = true;
dad0d04f Fariya Fatima 2014-03-16 200 }
dad0d04f Fariya Fatima 2014-03-16 201
dad0d04f Fariya Fatima 2014-03-16 202 msg[7] |= cpu_to_le16(vap_id << 8);
dad0d04f Fariya Fatima 2014-03-16 203
dad0d04f Fariya Fatima 2014-03-16 204 status = adapter->host_intf_write_pkt(common->priv,
dad0d04f Fariya Fatima 2014-03-16 205 (u8 *)msg,
dad0d04f Fariya Fatima 2014-03-16 206 skb->len);
dad0d04f Fariya Fatima 2014-03-16 207 if (status)
dad0d04f Fariya Fatima 2014-03-16 208 rsi_dbg(ERR_ZONE, "%s: Failed to write the packet\n", __func__);
dad0d04f Fariya Fatima 2014-03-16 209
dad0d04f Fariya Fatima 2014-03-16 210 err:
dad0d04f Fariya Fatima 2014-03-16 @211 rsi_indicate_tx_status(common->priv, skb, status);
dad0d04f Fariya Fatima 2014-03-16 212 return status;
dad0d04f Fariya Fatima 2014-03-16 213 }:::::: The code at line 211 was first introduced by commit
:::::: dad0d04fa7ba41ce603a01e8e64967650303e9a2 rsi: Add RS9113 wireless driver
:::::: TO: Fariya Fatima <[email protected]> :::::: CC: John W. Linville <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
cover xen-netback: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:46:45 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Delete an unnecessary assignment in connect_rings()
Delete an unnecessary goto statement in connect_rings()
Replace a variable initialisation by an assignment in read_xenbus_vif_flags() Replace a variable initialisation by an assignment in xen_register_watchers() Delete an unnecessary variable initialisation in xen_register_watchers()
drivers/net/xen-netback/xenbus.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
Signature · 1 line
2.6.3
cover xen-netback: Fine-tuning for three function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:46:45 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Delete an unnecessary assignment in connect_rings()
Delete an unnecessary goto statement in connect_rings()
Replace a variable initialisation by an assignment in read_xenbus_vif_flags() Replace a variable initialisation by an assignment in xen_register_watchers() Delete an unnecessary variable initialisation in xen_register_watchers()
drivers/net/xen-netback/xenbus.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/5 xen-netback: Delete an unnecessary assignment in connect_rings()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 17:32:40 +0100
Remove the assignment for a local variable because its value is not changed compared to the one from a previous function call.
--- drivers/net/xen-netback/xenbus.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/xen-netback/xenbus.c +0 -1
@@ -941,7 +941,6 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) goto err; } - err =0 ; err:/* Regular return falls through with err = 0 */ kfree (xspath);return err;
Signature · 1 line
2.6.3
PATCH 1/5 xen-netback: Delete an unnecessary assignment in connect_rings()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 17:32:40 +0100
Remove the assignment for a local variable because its value is not changed compared to the one from a previous function call.
--- drivers/net/xen-netback/xenbus.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/xen-netback/xenbus.c +0 -1
@@ -941,7 +941,6 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue) goto err; } - err =0 ; err:/* Regular return falls through with err == 0 */ kfree (xspath);return err;
Signature · 1 line
2.6.3
PATCH 2/5 xen-netback: Delete an unnecessary goto statement in connect_rings()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 17:50:21 +0100
One goto statement referred to a source code position directly behind it. Thus omit such an unnecessary jump.
--- drivers/net/xen-netback/xenbus.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/xen-netback/xenbus.c +1 -3
@@ -933,13 +933,11 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)/* Map the shared frame, irq etc. */ err =xenvif_connect (queue, tx_ring_ref, rx_ring_ref, tx_evtchn, rx_evtchn); -if (err) { +if (err)xenbus_dev_fatal (dev, err,"mapping shared-frames %lu/%lu port tx %u rx %u" , tx_ring_ref, rx_ring_ref, tx_evtchn, rx_evtchn); - goto err; - } err:/* Regular return falls through with err = 0 */ kfree (xspath);
Signature · 1 line
2.6.3
PATCH 2/5 xen-netback: Delete an unnecessary goto statement in connect_rings()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 17:50:21 +0100
One goto statement referred to a source code position directly behind it. Thus omit such an unnecessary jump.
--- drivers/net/xen-netback/xenbus.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/xen-netback/xenbus.c +1 -3
@@ -933,13 +933,11 @@ static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)/* Map the shared frame, irq etc. */ err =xenvif_connect (queue, tx_ring_ref, rx_ring_ref, tx_evtchn, rx_evtchn); -if (err) { +if (err)xenbus_dev_fatal (dev, err,"mapping shared-frames %lu/%lu port tx %u rx %u" , tx_ring_ref, rx_ring_ref, tx_evtchn, rx_evtchn); - goto err; - } err:/* Regular return falls through with err == 0 */ kfree (xspath);
Signature · 1 line
2.6.3
PATCH 3/5 xen-netback: Replace a variable initialisation by an assignment in read_xenbus_vif_flags()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:01:57 +0100
Replace an explicit initialisation for one local variable at the beginning by an assignment.
--- drivers/net/xen-netback/xenbus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/xen-netback/xenbus.c +4 -3
@@ -946,7 +946,7 @@ err: /* Regular return falls through with err = 0 */static int read_xenbus_vif_flags (struct backend_info *be) { -struct xenvif *vif = be->vif; +struct xenvif *vif;struct xenbus_device *dev = be->dev;unsigned int rx_copy;int err, val;
@@ -968,13 +968,14 @@ static int read_xenbus_vif_flags(struct backend_info *be)if (xenbus_scanf (XBT_NIL , dev->otherend,"feature-rx-notify" ,"%d" , &val) <0 ) val =0 ; + vif = be->vif;if (!val) {/* - Reduce drain timeout to poll more frequently for * Rx requests. * - Disable Rx stall detection. */ - be->vif->drain_timeout =msecs_to_jiffies (30 ); - be->vif->stall_timeout =0 ; + vif->drain_timeout =msecs_to_jiffies (30 ); + vif->stall_timeout =0 ; } if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
Signature · 1 line
2.6.3
PATCH 3/5 xen-netback: Replace a variable initialisation by an assignment in read_xenbus_vif_flags()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:01:57 +0100
Replace an explicit initialisation for one local variable at the beginning by an assignment.
--- drivers/net/xen-netback/xenbus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/xen-netback/xenbus.c +4 -3
@@ -946,7 +946,7 @@ err: /* Regular return falls through with err == 0 */static int read_xenbus_vif_flags (struct backend_info *be) { -struct xenvif *vif = be->vif; +struct xenvif *vif;struct xenbus_device *dev = be->dev;unsigned int rx_copy;int err, val;
@@ -968,13 +968,14 @@ static int read_xenbus_vif_flags(struct backend_info *be)if (xenbus_scanf (XBT_NIL , dev->otherend,"feature-rx-notify" ,"%d" , &val) <0 ) val =0 ; + vif = be->vif;if (!val) {/* - Reduce drain timeout to poll more frequently for * Rx requests. * - Disable Rx stall detection. */ - be->vif->drain_timeout =msecs_to_jiffies (30 ); - be->vif->stall_timeout =0 ; + vif->drain_timeout =msecs_to_jiffies (30 ); + vif->stall_timeout =0 ; } if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
Signature · 1 line
2.6.3
PATCH 4/5 xen-netback: Replace a variable initialisation by an assignment in xen_register_watchers()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:23:16 +0100
Replace an explicit initialisation for one local variable at the beginning by an assignment.
--- drivers/net/xen-netback/xenbus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/xen-netback/xenbus.c +2 -1
@@ -687,11 +687,12 @@ static int xen_register_watchers(struct xenbus_device *dev, struct xenvif *vif) {int err =0 ;char *node; -unsigned maxlen =strlen (dev->nodename) +sizeof ("/rate" ); +unsigned maxlen;if (vif->credit_watch.node)return -EADDRINUSE ; + maxlen =strlen (dev->nodename) +sizeof ("/rate" ); node =kmalloc (maxlen,GFP_KERNEL );if (!node)return -ENOMEM ;
Signature · 1 line
2.6.3
PATCH 4/5 xen-netback: Replace a variable initialisation by an assignment in xen_register_watchers()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:23:16 +0100
Replace an explicit initialisation for one local variable at the beginning by an assignment.
--- drivers/net/xen-netback/xenbus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/xen-netback/xenbus.c +2 -1
@@ -687,11 +687,12 @@ static int xen_register_watchers(struct xenbus_device *dev, struct xenvif *vif) {int err =0 ;char *node; -unsigned maxlen =strlen (dev->nodename) +sizeof ("/rate" ); +unsigned maxlen;if (vif->credit_watch.node)return -EADDRINUSE ; + maxlen =strlen (dev->nodename) +sizeof ("/rate" ); node =kmalloc (maxlen,GFP_KERNEL );if (!node)return -ENOMEM ;
Signature · 1 line
2.6.3
PATCH 5/5 xen-netback: Delete an unnecessary variable initialisation in xen_register_watchers()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:28:26 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/xen-netback/xenbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/xen-netback/xenbus.c +1 -1
@@ -685,7 +685,7 @@ static void xen_net_rate_changed(struct xenbus_watch *watch,static int xen_register_watchers (struct xenbus_device *dev,struct xenvif *vif) { -int err =0 ; +int err;char *node;unsigned maxlen;
Signature · 1 line
2.6.3
PATCH 5/5 xen-netback: Delete an unnecessary variable initialisation in xen_register_watchers()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 18:28:26 +0100
Omit explicit initialisation at the beginning for one local variable that is redefined before its first use.
--- drivers/net/xen-netback/xenbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/xen-netback/xenbus.c +1 -1
@@ -685,7 +685,7 @@ static void xen_net_rate_changed(struct xenbus_watch *watch,static int xen_register_watchers (struct xenbus_device *dev,struct xenvif *vif) { -int err =0 ; +int err;char *node;unsigned maxlen;
Signature · 1 line
2.6.3
Re: [PATCH 3/3] net-iwlegacy: Another refactoring for il_eeprom_init()
In reply to SF Markus ElfringQuoted 15 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 1 Jan 2016 21:16:01 +0100Rename a jump label according to the current Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/net/wireless/intel/iwlegacy/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/intel/iwlegacy/common.c +0
-0
drivers/net/wireless/intel/iwlegacy/common.c il_eeprom_init(struct il_priv *il) · line 762
Quoted 5 lines
drivers/net/wireless/intel/iwlegacy/common.c +1
-1@@ -759,7 +759,7 @@ il_eeprom_init(struct il_priv *il) IL_EEPROM_ACCESS_TIMEOUT);if (ret <0 ) {IL_ERR ("Time out reading EEPROM[%d]\n" , addr); - goto done; + goto release_semaphore;
Current code looks good.
Quoted 15 lines
drivers/net/wireless/intel/iwlegacy/common.c +1
-2} r =_il_rd (il,CSR_EEPROM_REG ); e[addr /2 ] =cpu_to_le16 (r >>16 );@@ -769,7 +769,7 @@ il_eeprom_init(struct il_priv *il) il_eeprom_query16(il, EEPROM_VERSION)); ret =0 ; -done: +release_semaphore: il->ops->eeprom_release_semaphore (il);if (ret) { --2.6.3
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-Souptick
PATCH v2 1/3 rsi: Delete unnecessary variable initialisations in rsi_send_mgmt_pkt()
In reply to kbuild test robotFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 19:22:36 +0100
Omit explicit initialisation at the beginning for four local variables which are redefined before their first use.
--- drivers/net/wireless/rsi/rsi_91x_pkt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/rsi/rsi_91x_pkt.c +4 -4
@@ -123,15 +123,15 @@ int rsi_send_mgmt_pkt(struct rsi_common *common, struct sk_buff *skb) {struct rsi_hw *adapter = common->priv; -struct ieee80211_hdr *wh =NULL ; +struct ieee80211_hdr *wh;struct ieee80211_tx_info *info; -struct ieee80211_bss_conf *bss =NULL ; +struct ieee80211_bss_conf *bss;struct ieee80211_hw *hw = adapter->hw;struct ieee80211_conf *conf = &hw->conf;struct skb_info *tx_params;int status = -E2BIG ; -__le16 *msg =NULL ; -u8 extnd_size =0 ; +__le16 *msg; +u8 extnd_size;u8 vap_id =0 ; info =IEEE80211_SKB_CB (skb);
Signature · 1 line
2.6.3
Jonathan Cameron
maintainerRe: [PATCH] iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection
In reply to SF Markus ElfringQuoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 26 Dec 2015 13:53:15 +0100This 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]>
If we are going to change this, I would prefer to see more useful local error messages and direct returns rather than jumping to a very generic message at the end.
I'm also less than keen on jumping into conditionals as I find it slightly less readable.
We might technically be 'simplifying' the code, but in this case the gain is very minor for a fair bit of code churn...
Thanks,
Jonathan
Quoted 9 lines
--- drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)drivers/iio/adc/qcom-spmi-vadc.c +0
-0
drivers/iio/adc/qcom-spmi-vadc.c static int vadc_measure_ref_points(struct vadc_priv *vadc) · line 427
Quoted 5 lines
drivers/iio/adc/qcom-spmi-vadc.c +1
-1@@ -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;
In this first case we have already had a report that a conversion failed. I suppose adding that it was during reference point measurement 'might' be useful additional information. I'm not really convinced of it does however... Hence I'd drop reporting it entirely in this function.
drivers/iio/adc/qcom-spmi-vadc.c static int vadc_measure_ref_points(struct vadc_priv *vadc) · line 439
Quoted 12 lines
drivers/iio/adc/qcom-spmi-vadc.c +1
-1/* 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 ;
I think this one indicates we can't actually read anything at all for some reason... It's the only form of error we won't have effectively already reported so is worthy of some sort of debug message...
Quoted 36 lines
drivers/iio/adc/qcom-spmi-vadc.c +7
-6- 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; }
cover NFC-mei_phy: Fine-tuning for two function implementations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 21:47:30 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Refactoring for mei_nfc_connect()
Refactoring for mei_nfc_if_version()
Delete an unnecessary variable initialisation in mei_nfc_if_version()
drivers/nfc/mei_phy.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/3 NFC-mei_phy: Refactoring for mei_nfc_connect()
From: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 21:21:24 +0100
This issue was detected by using the Coccinelle software.
Adjust jump targets according to the current Linux coding style convention.
--- drivers/nfc/mei_phy.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/nfc/mei_phy.c +6 -7
@@ -173,8 +173,8 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy) reply =kzalloc (connect_resp_length,GFP_KERNEL );if (!reply) { -kfree (cmd); -return -ENOMEM ; + r = -ENOMEM ; + goto free_cmd; } connect_resp = (struct mei_nfc_connect_resp *)reply->data;
@@ -189,7 +189,7 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy) r =mei_cldev_send (phy->cldev, (u8 *)cmd, connect_length);if (r <0 ) {pr_err ("Could not send connect cmd %d\n" , r); - goto err; + goto free_reply; } bytes_recv = mei_cldev_recv(phy->cldev, (u8 *)reply,
@@ -197,7 +197,7 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy)if (bytes_recv <0 ) { r = bytes_recv;pr_err ("Could not read connect response %d\n" , r); - goto err; + goto free_reply; }MEI_DUMP_NFC_HDR ("connect reply" , &reply->hdr);
@@ -210,11 +210,10 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy) connect_resp->me_hotfix, connect_resp->me_build); r =0 ; - -err: +free_reply:kfree (reply); +free_cmd:kfree (cmd); -return r; }
Signature · 1 line
2.6.3
PATCH 2/3 NFC-mei_phy: Refactoring for mei_nfc_if_version()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sat, 2 Jan 2016 21:33:04 +0100
Rename a jump label according to the current Linux coding style convention.
--- drivers/nfc/mei_phy.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/nfc/mei_phy.c +2 -3
@@ -136,7 +136,7 @@ static int mei_nfc_if_version(struct nfc_mei_phy *phy)if (bytes_recv <0 || bytes_recv <sizeof (struct mei_nfc_reply )) {pr_err ("Could not read IF version\n" ); r = -EIO ; - goto err; + goto free_reply; } version = (struct mei_nfc_if_version *)reply->data;
@@ -144,8 +144,7 @@ static int mei_nfc_if_version(struct nfc_mei_phy *phy) phy->fw_ivn = version->fw_ivn; phy->vendor_id = version->vendor_id; phy->radio_type = version->radio_type; - -err: +free_reply:kfree (reply);return r; }
Signature · 1 line
2.6.3