2014-07-29 15:23:57

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/9] use correct structure type name in sizeof

These patches fix typos in the name of a type referenced in a sizeof
command. These problems are not caught by the compiler, because they have
no impact on execution - the size of a pointer is independent of the size
of the pointed value.

The semantic patch that finds these problems is shown below
(http://coccinelle.lip6.fr/). This semantic patch distinguishes between
structures that are defined in C files, and thus are expected to be visible
in only that file, and structures that are defined in header files, which
could potential be visible everywhere. This distinction seems to be
unnecessary in practice, though.

<smpl>
virtual after_start

@initialize:ocaml@
@@

type fl = C of string | H

let structures = Hashtbl.create 101
let restarted = ref false

let add_if_not_present _ =
if not !restarted
then
begin
restarted := true;
let it = new iteration() in
it#add_virtual_rule After_start;
it#register()
end

let hashadd str file =
let cell =
try Hashtbl.find structures str
with Not_found ->
let cell = ref [] in
Hashtbl.add structures str cell;
cell in
if not (List.mem file !cell) then cell := file :: !cell

let get_file fl =
if Filename.check_suffix fl ".c"
then C fl
else H

@script:ocaml depends on !after_start@
@@
add_if_not_present()

@r depends on !after_start@
identifier nm;
position p;
@@

struct nm@p { ... };

@script:ocaml@
nm << r.nm;
p << r.p;
@@

hashadd nm (get_file (List.hd p).file)

// -------------------------------------------------------------------------

@sz depends on after_start@
identifier nm;
position p;
@@

sizeof(struct nm@p *)

@script:ocaml@
nm << sz.nm;
p << sz.p;
@@

try
let allowed = !(Hashtbl.find structures nm) in
if List.mem H allowed or List.mem (get_file (List.hd p).file) allowed
then ()
else print_main nm p
with Not_found -> print_main nm p
</smpl>


2014-07-29 15:20:05

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/9] reiserfs: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
fs/reiserfs/resize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 6052d32..e69051b 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -99,7 +99,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
*/
copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr;
copy_size =
- copy_size * sizeof(struct reiserfs_list_bitmap_node *);
+ copy_size * sizeof(struct reiserfs_bitmap_node *);
for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
struct reiserfs_bitmap_node **node_tmp;
jb = SB_JOURNAL(s)->j_list_bitmap + i;

2014-07-29 15:20:03

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 5/9] scsi: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/scsi/eata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index 813dd5c..4caf221 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -811,7 +811,7 @@ struct mscp {
struct sg_list *sglist; /* pointer to the allocated SG list */
};

-#define CP_TAIL_SIZE (sizeof(struct sglist *) + sizeof(dma_addr_t))
+#define CP_TAIL_SIZE (sizeof(struct sg_list *) + sizeof(dma_addr_t))

struct hostdata {
struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */

2014-07-29 15:20:50

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 9/9] uwb/whci: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/uwb/whci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/uwb/whci.c b/drivers/uwb/whci.c
index c9df8ba..46b7cfc 100644
--- a/drivers/uwb/whci.c
+++ b/drivers/uwb/whci.c
@@ -175,7 +175,7 @@ static int whci_probe(struct pci_dev *pci, const struct pci_device_id *id)

err = -ENOMEM;
card = kzalloc(sizeof(struct whci_card)
- + sizeof(struct whci_dev *) * (n_caps + 1),
+ + sizeof(struct umc_dev *) * (n_caps + 1),
GFP_KERNEL);
if (card == NULL)
goto error_kzalloc;

2014-07-29 15:21:35

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 8/9] iwlegacy: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/net/wireless/iwlegacy/common.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/iwlegacy/common.c b/drivers/net/wireless/iwlegacy/common.c
index 03de746..2c4fa49 100644
--- a/drivers/net/wireless/iwlegacy/common.c
+++ b/drivers/net/wireless/iwlegacy/common.c
@@ -2980,7 +2980,8 @@ il_tx_queue_alloc(struct il_priv *il, struct il_tx_queue *txq, u32 id)
/* Driver ilate data, only for Tx (not command) queues,
* not shared with device. */
if (id != il->cmd_queue) {
- txq->skbs = kcalloc(TFD_QUEUE_SIZE_MAX, sizeof(struct skb *),
+ txq->skbs = kcalloc(TFD_QUEUE_SIZE_MAX,
+ sizeof(struct sk_buff *),
GFP_KERNEL);
if (!txq->skbs) {
IL_ERR("Fail to alloc skbs\n");

2014-07-29 15:21:59

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 7/9] scsi: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/scsi/u14-34f.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 4e76fe8..617d72a 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -585,7 +585,7 @@ struct mscp {
struct sg_list *sglist; /* pointer to the allocated SG list */
};

-#define CP_TAIL_SIZE (sizeof(struct sglist *) + sizeof(dma_addr_t))
+#define CP_TAIL_SIZE (sizeof(struct sg_list *) + sizeof(dma_addr_t))

struct hostdata {
struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */

2014-07-29 15:22:00

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/gpio/devres.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 65978cf..4a63207 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -84,7 +84,7 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
struct gpio_desc **dr;
struct gpio_desc *desc;

- dr = devres_alloc(devm_gpiod_release, sizeof(struct gpiod_desc *),
+ dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
GFP_KERNEL);
if (!dr)
return ERR_PTR(-ENOMEM);

2014-07-29 15:19:58

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/9] drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index cda8388..255590f 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -227,7 +227,7 @@ static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
return 0;

vpfe_dev->clks = kzalloc(vpfe_cfg->num_clocks *
- sizeof(struct clock *), GFP_KERNEL);
+ sizeof(struct clk *), GFP_KERNEL);
if (vpfe_dev->clks == NULL) {
v4l2_err(vpfe_dev->pdev->driver, "Memory allocation failed\n");
return -ENOMEM;

2014-07-29 15:23:28

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 3/9] i40e: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 821fcc1..b913c27 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -6137,7 +6137,7 @@ static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)

if (alloc_qvectors) {
/* allocate memory for q_vector pointers */
- size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
+ size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
vsi->q_vectors = kzalloc(size, GFP_KERNEL);
if (!vsi->q_vectors) {
ret = -ENOMEM;

2014-07-29 15:23:59

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 2/9] CAPI: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>

Correct typo in the name of the type given to sizeof. Because it is the
size of a pointer that is wanted, the typo has no impact on compilation or
execution.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
semantic patch used can be found in message 0 of this patch series.

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

---
drivers/isdn/capi/capi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index f9a87ed..6a2df32 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1260,7 +1260,7 @@ static int __init capinc_tty_init(void)
if (capi_ttyminors <= 0)
capi_ttyminors = CAPINC_NR_PORTS;

- capiminors = kzalloc(sizeof(struct capi_minor *) * capi_ttyminors,
+ capiminors = kzalloc(sizeof(struct capiminor *) * capi_ttyminors,
GFP_KERNEL);
if (!capiminors)
return -ENOMEM;

2014-07-29 20:22:26

by Brown, Aaron F

[permalink] [raw]
Subject: Re: [PATCH 3/9] i40e: use correct structure type name in sizeof

On Tue, 2014-07-29 at 17:16 +0200, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> Correct typo in the name of the type given to sizeof. Because it is the
> size of a pointer that is wanted, the typo has no impact on compilation or
> execution.
>
> This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> semantic patch used can be found in message 0 of this patch series.
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks Julia, I have added your patch to our (Jeff's) queue.
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2014-07-30 08:28:03

by Alexandre Courbot

[permalink] [raw]
Subject: Re: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof

On Wed, Jul 30, 2014 at 12:16 AM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> Correct typo in the name of the type given to sizeof. Because it is the
> size of a pointer that is wanted, the typo has no impact on compilation or
> execution.
>
> This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> semantic patch used can be found in message 0 of this patch series.

Acked-by: Alexandre Courbot <[email protected]>

Interestingly the compiler never complains despite gpiod_desc not
being a declared type...

Thanks!

2014-07-30 08:49:24

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof



On Wed, 30 Jul 2014, Alexandre Courbot wrote:

> On Wed, Jul 30, 2014 at 12:16 AM, Julia Lawall <[email protected]> wrote:
> > From: Julia Lawall <[email protected]>
> >
> > Correct typo in the name of the type given to sizeof. Because it is the
> > size of a pointer that is wanted, the typo has no impact on compilation or
> > execution.
> >
> > This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> > semantic patch used can be found in message 0 of this patch series.
>
> Acked-by: Alexandre Courbot <[email protected]>
>
> Interestingly the compiler never complains despite gpiod_desc not
> being a declared type...

The compiler doesn't care. A pointer is a pointer, regardless of the
type.

julia

2014-07-31 02:14:09

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 2/9] CAPI: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>
Date: Tue, 29 Jul 2014 17:16:44 +0200

> From: Julia Lawall <[email protected]>
>
> Correct typo in the name of the type given to sizeof. Because it is the
> size of a pointer that is wanted, the typo has no impact on compilation or
> execution.
>
> This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> semantic patch used can be found in message 0 of this patch series.
>
> Signed-off-by: Julia Lawall <[email protected]>

Relatively harmless, so applied to net-next, thanks.

2014-07-31 02:14:22

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 3/9] i40e: use correct structure type name in sizeof

From: Julia Lawall <[email protected]>
Date: Tue, 29 Jul 2014 17:16:45 +0200

> From: Julia Lawall <[email protected]>
>
> Correct typo in the name of the type given to sizeof. Because it is the
> size of a pointer that is wanted, the typo has no impact on compilation or
> execution.
>
> This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> semantic patch used can be found in message 0 of this patch series.
>
> Signed-off-by: Julia Lawall <[email protected]>

I'll let the Intel driver folks pick this one up, thanks!

2015-11-09 20:48:18

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 1/9] drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c: use correct structure type name in sizeof

Hi Julia,

Thank you for the patch.

On Tuesday 29 July 2014 17:16:43 Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> Correct typo in the name of the type given to sizeof. Because it is the
> size of a pointer that is wanted, the typo has no impact on compilation or
> execution.
>
> This problem was found using Coccinelle (http://coccinelle.lip6.fr/). The
> semantic patch used can be found in message 0 of this patch series.
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
> b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c index
> cda8388..255590f 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
> @@ -227,7 +227,7 @@ static int vpfe_enable_clock(struct vpfe_device
> *vpfe_dev) return 0;
>
> vpfe_dev->clks = kzalloc(vpfe_cfg->num_clocks *
> - sizeof(struct clock *), GFP_KERNEL);
> + sizeof(struct clk *), GFP_KERNEL);

I'd use sizeof(*vpfe_dev->clks) to avoid such issues.

Apart from that,

Acked-by: Laurent Pinchart <[email protected]>

I've applied the patch to my tree with the above change, there's no need to
resubmit if you agree with the proposal.

> if (vpfe_dev->clks == NULL) {
> v4l2_err(vpfe_dev->pdev->driver, "Memory allocation failed\n");
> return -ENOMEM;

--
Regards,

Laurent Pinchart