Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/9] use correct structure type name in sizeof
@ 2014-07-29 15:16 Julia Lawall
  2014-07-29 15:16 ` [PATCH 6/9] gpiolib: devres: " Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2014-07-29 15:16 UTC (permalink / raw)
  To: linux-wireless
  Cc: devel, linux-ia64, linux-scsi, e1000-devel, toralf.foerster,
	linux-usb, kernel-janitors, reiserfs-devel, linux-kernel,
	linux-gpio, hmh, netdev, ceph-devel, linux-media

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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof
  2014-07-29 15:16 [PATCH 0/9] use correct structure type name in sizeof Julia Lawall
@ 2014-07-29 15:16 ` Julia Lawall
  2014-07-30  8:27   ` Alexandre Courbot
  2014-08-08 13:26   ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Julia Lawall @ 2014-07-29 15:16 UTC (permalink / raw)
  To: Linus Walleij
  Cc: kernel-janitors, linux-ia64, ceph-devel, toralf.foerster, hmh,
	Alexandre Courbot, linux-gpio, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

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 <Julia.Lawall@lip6.fr>

---
 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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof
  2014-07-29 15:16 ` [PATCH 6/9] gpiolib: devres: " Julia Lawall
@ 2014-07-30  8:27   ` Alexandre Courbot
  2014-07-30  8:48     ` Julia Lawall
  2014-08-08 13:26   ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Alexandre Courbot @ 2014-07-30  8:27 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Linus Walleij, kernel-janitors, linux-ia64, ceph-devel,
	toralf.foerster, hmh, linux-gpio@vger.kernel.org,
	Linux Kernel Mailing List

On Wed, Jul 30, 2014 at 12:16 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> 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 <acourbot@nvidia.com>

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

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof
  2014-07-30  8:27   ` Alexandre Courbot
@ 2014-07-30  8:48     ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2014-07-30  8:48 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Linus Walleij, kernel-janitors, linux-ia64, ceph-devel,
	toralf.foerster, hmh, linux-gpio@vger.kernel.org,
	Linux Kernel Mailing List



On Wed, 30 Jul 2014, Alexandre Courbot wrote:

> On Wed, Jul 30, 2014 at 12:16 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> > From: Julia Lawall <Julia.Lawall@lip6.fr>
> >
> > 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 <acourbot@nvidia.com>
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 6/9] gpiolib: devres: use correct structure type name in sizeof
  2014-07-29 15:16 ` [PATCH 6/9] gpiolib: devres: " Julia Lawall
  2014-07-30  8:27   ` Alexandre Courbot
@ 2014-08-08 13:26   ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2014-08-08 13:26 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, linux-ia64, ceph-devel, toralf.foerster, hmh,
	Alexandre Courbot, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org

On Tue, Jul 29, 2014 at 5:16 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> 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 <Julia.Lawall@lip6.fr>

Patch applied with Alexandre's ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-08 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-29 15:16 [PATCH 0/9] use correct structure type name in sizeof Julia Lawall
2014-07-29 15:16 ` [PATCH 6/9] gpiolib: devres: " Julia Lawall
2014-07-30  8:27   ` Alexandre Courbot
2014-07-30  8:48     ` Julia Lawall
2014-08-08 13:26   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox