public inbox for linux-kernel@vger.kernel.org
 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 1/9] drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c: " Julia Lawall
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Julia Lawall @ 2014-07-29 15:16 UTC (permalink / raw)
  To: linux-wireless
  Cc: kernel-janitors, linux-ia64, ceph-devel, toralf.foerster, hmh,
	linux-gpio, reiserfs-devel, netdev, linux-kernel, linux-media,
	devel, e1000-devel, linux-scsi, linux-usb

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] 17+ messages in thread

end of thread, other threads:[~2015-11-09 20:48 UTC | newest]

Thread overview: 17+ 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 1/9] drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c: " Julia Lawall
2015-11-09 20:48   ` Laurent Pinchart
2014-07-29 15:16 ` [PATCH 2/9] CAPI: " Julia Lawall
2014-07-31  2:14   ` David Miller
2014-07-29 15:16 ` [PATCH 3/9] i40e: " Julia Lawall
2014-07-29 20:22   ` Brown, Aaron F
2014-07-31  2:14   ` David Miller
2014-07-29 15:16 ` [PATCH 4/9] reiserfs: " Julia Lawall
2014-07-29 15:16 ` [PATCH 5/9] scsi: " 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
2014-07-29 15:16 ` [PATCH 7/9] scsi: " Julia Lawall
2014-07-29 15:16 ` [PATCH 8/9] iwlegacy: " Julia Lawall
2014-07-29 15:16 ` [PATCH 9/9] uwb/whci: " Julia Lawall

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