Joe Hershberger | 63d9859 | 2016-08-08 11:28:37 -0500 | [diff] [blame] | 1 | /// Use mdio_alloc and mdio_register instead of miiphy_register |
| 2 | /// |
| 3 | //# Stop using the oldest mii interface in drivers |
| 4 | // |
| 5 | // Confidence: High |
| 6 | // Copyright: (C) 2016 Joe Hershberger. GPLv2. |
| 7 | // Comments: |
| 8 | // Options: --include-headers --recursive-includes --local-includes -I include |
| 9 | |
| 10 | @ mii_reg @ |
| 11 | expression devname; |
| 12 | identifier readfunc, writefunc; |
| 13 | @@ |
| 14 | |
| 15 | + int retval; |
| 16 | - miiphy_register(devname, readfunc, writefunc); |
| 17 | + struct mii_dev *mdiodev = mdio_alloc(); |
| 18 | + if (!mdiodev) return -ENOMEM; |
| 19 | + strncpy(mdiodev->name, devname, MDIO_NAME_LEN); |
| 20 | + mdiodev->read = readfunc; |
| 21 | + mdiodev->write = writefunc; |
| 22 | + |
| 23 | + retval = mdio_register(mdiodev); |
| 24 | + if (retval < 0) return retval; |
| 25 | |
| 26 | @ update_read_sig @ |
| 27 | identifier mii_reg.readfunc; |
| 28 | identifier name0, addr0, reg0, output; |
| 29 | type addrT, outputT; |
| 30 | @@ |
| 31 | |
| 32 | - readfunc ( |
| 33 | - const char *name0, |
| 34 | - addrT addr0, |
| 35 | - addrT reg0, |
| 36 | - outputT *output |
| 37 | - ) |
| 38 | + readfunc ( |
| 39 | + struct mii_dev *bus, |
| 40 | + int addr0, |
| 41 | + int devad, |
| 42 | + int reg0 |
| 43 | + ) |
| 44 | { |
| 45 | ... |
| 46 | } |
| 47 | |
| 48 | @ update_read_impl @ |
| 49 | identifier mii_reg.readfunc; |
| 50 | identifier update_read_sig.output; |
| 51 | type update_read_sig.outputT; |
| 52 | constant c; |
| 53 | identifier retvar; |
| 54 | expression E; |
| 55 | @@ |
| 56 | |
| 57 | readfunc (...) |
| 58 | { |
| 59 | + outputT output = 0; |
| 60 | ... |
| 61 | ( |
| 62 | - return 0; |
| 63 | + return *output; |
| 64 | | |
| 65 | return c; |
| 66 | | |
| 67 | - return retvar; |
| 68 | + if (retvar < 0) |
| 69 | + return retvar; |
| 70 | + return *output; |
| 71 | | |
| 72 | - return E; |
| 73 | + int retval = E; |
| 74 | + if (retval < 0) |
| 75 | + return retval; |
| 76 | + return *output; |
| 77 | ) |
| 78 | } |
| 79 | |
| 80 | @ update_read_impl2 @ |
| 81 | identifier mii_reg.readfunc; |
| 82 | identifier update_read_sig.output; |
| 83 | @@ |
| 84 | |
| 85 | readfunc (...) |
| 86 | { |
| 87 | <... |
| 88 | ( |
| 89 | - *output |
| 90 | + output |
| 91 | | |
| 92 | - output |
| 93 | + &output |
| 94 | ) |
| 95 | ...> |
| 96 | } |
| 97 | |
| 98 | @ update_read_name @ |
| 99 | identifier mii_reg.readfunc; |
| 100 | identifier update_read_sig.name0; |
| 101 | @@ |
| 102 | readfunc (...) { |
| 103 | <... |
| 104 | - name0 |
| 105 | + bus->name |
| 106 | ...> |
| 107 | } |
| 108 | |
| 109 | @ update_write_sig @ |
| 110 | identifier mii_reg.writefunc; |
| 111 | identifier name0, addr0, reg0, value0; |
| 112 | type addrT, valueT; |
| 113 | typedef u16; |
| 114 | @@ |
| 115 | |
| 116 | - writefunc ( |
| 117 | - const char *name0, |
| 118 | - addrT addr0, |
| 119 | - addrT reg0, |
| 120 | - valueT value0 |
| 121 | - ) |
| 122 | + writefunc ( |
| 123 | + struct mii_dev *bus, |
| 124 | + int addr0, |
| 125 | + int devad, |
| 126 | + int reg0, |
| 127 | + u16 value0 |
| 128 | + ) |
| 129 | { |
| 130 | ... |
| 131 | } |
| 132 | |
| 133 | @ update_write_name @ |
| 134 | identifier mii_reg.writefunc; |
| 135 | identifier update_write_sig.name0; |
| 136 | @@ |
| 137 | writefunc (...) { |
| 138 | <... |
| 139 | - name0 |
| 140 | + bus->name |
| 141 | ...> |
| 142 | } |