mdio_register.cocci 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
/// Use mdio_alloc and mdio_register instead of miiphy_register
///
//# Stop using the oldest mii interface in drivers
//
// Confidence: High
// Copyright: (C) 2016 Joe Hershberger.  GPLv2.
// Comments:
// Options: --include-headers --recursive-includes --local-includes -I include

@ mii_reg @
expression devname;
identifier readfunc, writefunc;
@@

+ int retval;
- miiphy_register(devname, readfunc, writefunc);
+ struct mii_dev *mdiodev = mdio_alloc();
+ if (!mdiodev) return -ENOMEM;
+ strncpy(mdiodev->name, devname, MDIO_NAME_LEN);
+ mdiodev->read = readfunc;
+ mdiodev->write = writefunc;
+ 
+ retval = mdio_register(mdiodev);
+ if (retval < 0) return retval;

@ update_read_sig @
identifier mii_reg.readfunc;
identifier name0, addr0, reg0, output;
type addrT, outputT;
@@

- readfunc (
- 	const char *name0,
- 	addrT addr0,
- 	addrT reg0,
- 	outputT *output
- )
+ readfunc (
+ 	struct mii_dev *bus,
+ 	int addr0,
+ 	int devad,
+ 	int reg0
+ )
  {
  ...
  }

@ update_read_impl @
identifier mii_reg.readfunc;
identifier update_read_sig.output;
type update_read_sig.outputT;
constant c;
identifier retvar;
expression E;
@@

  readfunc (...)
  {
+ outputT output = 0;
  ...
(
- return 0;
+ return *output;
|
  return c;
|
- return retvar;
+ if (retvar < 0)
+ 	return retvar;
+ return *output;
|
- return E;
+ int retval = E;
+ if (retval < 0)
+ 	return retval;
+ return *output;
)
  }

@ update_read_impl2 @
identifier mii_reg.readfunc;
identifier update_read_sig.output;
@@

  readfunc (...)
  {
  <...
(
- *output
+ output
|
- output
+ &output
)
  ...>
  }

@ update_read_name @
identifier mii_reg.readfunc;
identifier update_read_sig.name0;
@@
  readfunc (...) {
  <...
- name0
+ bus->name
  ...>
  }

@ update_write_sig @
identifier mii_reg.writefunc;
identifier name0, addr0, reg0, value0;
type addrT, valueT;
typedef u16;
@@

- writefunc (
- 	const char *name0,
- 	addrT addr0,
- 	addrT reg0,
- 	valueT value0
- )
+ writefunc (
+ 	struct mii_dev *bus,
+ 	int addr0,
+ 	int devad,
+ 	int reg0,
+ 	u16 value0
+ )
  {
  ...
  }

@ update_write_name @
identifier mii_reg.writefunc;
identifier update_write_sig.name0;
@@
  writefunc (...) {
  <...
- name0
+ bus->name
  ...>
  }