2014-11-30 18:19:49

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/4] remove unneeded array

Remove an array or structure that only serves as the first argument to
memset. The complete semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x;
type T;
@@

{
... when any
-T x[...];
<+... when != x
- memset(x,...);
...+>
}

@@
identifier x,i;
@@

{
... when any
-struct i x;
<+... when != x
- memset(&x,...);
...+>
}
// </smpl>


2014-11-30 18:19:51

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 3/4] staging: unisys: remove unneeded structure

From: Julia Lawall <[email protected]>

Delete a local structure that is only used to be initialized by memset.

A semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x,i;
@@

{
... when any
-struct i x;
<+... when != x
- memset(&x,...);
...+>
}
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/staging/unisys/visorchipset/visorchipset_main.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/staging/unisys/visorchipset/visorchipset_main.c b/drivers/staging/unisys/visorchipset/visorchipset_main.c
index c8f7bea..7e6be32 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset_main.c
+++ b/drivers/staging/unisys/visorchipset/visorchipset_main.c
@@ -1940,7 +1940,6 @@ static HOSTADDRESS controlvm_get_channel_address(void)
static void
controlvm_periodic_work(struct work_struct *work)
{
- struct visorchipset_channel_info chanInfo;
struct controlvm_message inmsg;
BOOL gotACommand = FALSE;
BOOL handle_command_failed = FALSE;
@@ -1955,8 +1954,6 @@ controlvm_periodic_work(struct work_struct *work)
if (visorchipset_clientregwait && !clientregistered)
goto Away;

- memset(&chanInfo, 0, sizeof(struct visorchipset_channel_info));
-
Poll_Count++;
if (Poll_Count >= 250)
; /* keep going */

2014-11-30 18:20:16

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/4] usbip: remove unneeded structure

From: Julia Lawall <[email protected]>

Delete a local structure that is only used to be initialized by memset.

A semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x,i;
@@

{
... when any
-struct i x;
<+... when != x
- memset(&x,...);
...+>
}
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
tools/usb/usbip/src/usbipd.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 2f87f2d..2a7cd2b 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -91,7 +91,6 @@ static void usbipd_help(void)
static int recv_request_import(int sockfd)
{
struct op_import_request req;
- struct op_common reply;
struct usbip_exported_device *edev;
struct usbip_usb_device pdu_udev;
struct list_head *i;
@@ -100,7 +99,6 @@ static int recv_request_import(int sockfd)
int rc;

memset(&req, 0, sizeof(req));
- memset(&reply, 0, sizeof(reply));

rc = usbip_net_recv(sockfd, &req, sizeof(req));
if (rc < 0) {

2014-11-30 18:20:43

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 2/4] drivers/scsi/bfa/bfa_svc.c: remove unneeded structure

From: Julia Lawall <[email protected]>

Delete a local structure that is only used to be initialized by memset.

A semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x,i;
@@

{
... when any
-struct i x;
<+... when != x
- memset(&x,...);
...+>
}
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/scsi/bfa/bfa_svc.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index 625225f..cf46683 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -404,13 +404,10 @@ bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
enum bfa_plog_eid event,
u16 misc, struct fchs_s *fchdr)
{
- struct bfa_plog_rec_s lp;
u32 *tmp_int = (u32 *) fchdr;
u32 ints[BFA_PL_INT_LOG_SZ];

if (plog->plog_enabled) {
- memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
-
ints[0] = tmp_int[0];
ints[1] = tmp_int[1];
ints[2] = tmp_int[4];
@@ -424,13 +421,10 @@ bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
u32 pld_w0)
{
- struct bfa_plog_rec_s lp;
u32 *tmp_int = (u32 *) fchdr;
u32 ints[BFA_PL_INT_LOG_SZ];

if (plog->plog_enabled) {
- memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
-
ints[0] = tmp_int[0];
ints[1] = tmp_int[1];
ints[2] = tmp_int[4];

2014-11-30 18:21:07

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/4] target: remove unneeded array

From: Julia Lawall <[email protected]>

Delete a local array that is only used to be initialized by memset.

A semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x;
type T;
@@

{
... when any
-T x[...];
<+... when != x
- memset(x,...);
...+>
}
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/target/target_core_pr.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 4c261c3..a0f850b 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1429,14 +1429,12 @@ core_scsi3_decode_spec_i_port(
struct target_core_fabric_ops *tmp_tf_ops;
unsigned char *buf;
unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident;
- char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN];
+ char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN];
sense_reason_t ret;
u32 tpdl, tid_len = 0;
int dest_local_nexus;
u32 dest_rtpi = 0;

- memset(dest_iport, 0, 64);
-
local_se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun];
/*
* Allocate a struct pr_transport_id_holder and setup the
@@ -3059,7 +3057,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
struct t10_reservation *pr_tmpl = &dev->t10_pr;
unsigned char *buf;
unsigned char *initiator_str;
- char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN];
+ char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN];
u32 tid_len, tmp_tid_len;
int new_reg = 0, type, scope, matching_iname;
sense_reason_t ret;
@@ -3071,7 +3069,6 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}

- memset(dest_iport, 0, 64);
memset(i_buf, 0, PR_REG_ISID_ID_LEN);
se_tpg = se_sess->se_tpg;
tf_ops = se_tpg->se_tpg_tfo;

2014-12-01 08:39:25

by Valentina Manea

[permalink] [raw]
Subject: Re: [PATCH 4/4] usbip: remove unneeded structure

On Sun, Nov 30, 2014 at 8:14 PM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> Delete a local structure that is only used to be initialized by memset.
>
> A semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier x,i;
> @@
>
> {
> ... when any
> -struct i x;
> <+... when != x
> - memset(&x,...);
> ...+>
> }
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> tools/usb/usbip/src/usbipd.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
> index 2f87f2d..2a7cd2b 100644
> --- a/tools/usb/usbip/src/usbipd.c
> +++ b/tools/usb/usbip/src/usbipd.c
> @@ -91,7 +91,6 @@ static void usbipd_help(void)
> static int recv_request_import(int sockfd)
> {
> struct op_import_request req;
> - struct op_common reply;
> struct usbip_exported_device *edev;
> struct usbip_usb_device pdu_udev;
> struct list_head *i;
> @@ -100,7 +99,6 @@ static int recv_request_import(int sockfd)
> int rc;
>
> memset(&req, 0, sizeof(req));
> - memset(&reply, 0, sizeof(reply));
>
> rc = usbip_net_recv(sockfd, &req, sizeof(req));
> if (rc < 0) {
>

Acked-by: Valentina Manea <[email protected]>

2014-12-02 06:12:51

by Nicholas A. Bellinger

[permalink] [raw]
Subject: Re: [PATCH 1/4] target: remove unneeded array

On Sun, 2014-11-30 at 19:14 +0100, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> Delete a local array that is only used to be initialized by memset.
>
> A semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier x;
> type T;
> @@
>
> {
> ... when any
> -T x[...];
> <+... when != x
> - memset(x,...);
> ...+>
> }
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/target/target_core_pr.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>

Applied to target-pending/for-next.

Thanks Julia!

--nab