Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging:iio:ade7854: Remove read_reg_* duplications

The original code had a read function per data size; after updates, all
read functions tasks were centralized in a single function, but the old
signature was kept to maintain the module working without problems. This
patch removes a set of duplications associated with read_reg_*, and
update the areas that calling the old interface by the new one.

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Rodrigo Siqueira and committed by
Jonathan Cameron
8ea0fa7c e6182b2d

+15 -78
+1 -32
drivers/staging/iio/meter/ade7854-i2c.c
··· 110 110 return ret; 111 111 } 112 112 113 - static int ade7854_i2c_read_reg_8(struct device *dev, 114 - u16 reg_address, 115 - u8 *val) 116 - { 117 - return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 8); 118 - } 119 - 120 - static int ade7854_i2c_read_reg_16(struct device *dev, 121 - u16 reg_address, 122 - u16 *val) 123 - { 124 - return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 16); 125 - } 126 - 127 - static int ade7854_i2c_read_reg_24(struct device *dev, 128 - u16 reg_address, 129 - u32 *val) 130 - { 131 - return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 24); 132 - } 133 - 134 - static int ade7854_i2c_read_reg_32(struct device *dev, 135 - u16 reg_address, 136 - u32 *val) 137 - { 138 - return ade7854_i2c_read_reg(dev, reg_address, (u32 *)val, 32); 139 - } 140 - 141 113 static int ade7854_i2c_probe(struct i2c_client *client, 142 114 const struct i2c_device_id *id) 143 115 { ··· 121 149 return -ENOMEM; 122 150 st = iio_priv(indio_dev); 123 151 i2c_set_clientdata(client, indio_dev); 124 - st->read_reg_8 = ade7854_i2c_read_reg_8; 125 - st->read_reg_16 = ade7854_i2c_read_reg_16; 126 - st->read_reg_24 = ade7854_i2c_read_reg_24; 127 - st->read_reg_32 = ade7854_i2c_read_reg_32; 152 + st->read_reg = ade7854_i2c_read_reg; 128 153 st->write_reg = ade7854_i2c_write_reg; 129 154 st->i2c = client; 130 155 st->irq = client->irq;
+2 -33
drivers/staging/iio/meter/ade7854-spi.c
··· 94 94 st->tx[2] = reg_address & 0xFF; 95 95 96 96 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); 97 - if (ret) { 97 + if (ret < 0) { 98 98 dev_err(&st->spi->dev, "problem when reading register 0x%02X", 99 99 reg_address); 100 100 goto unlock; ··· 120 120 return ret; 121 121 } 122 122 123 - static int ade7854_spi_read_reg_8(struct device *dev, 124 - u16 reg_address, 125 - u8 *val) 126 - { 127 - return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 8); 128 - } 129 - 130 - static int ade7854_spi_read_reg_16(struct device *dev, 131 - u16 reg_address, 132 - u16 *val) 133 - { 134 - return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 16); 135 - } 136 - 137 - static int ade7854_spi_read_reg_24(struct device *dev, 138 - u16 reg_address, 139 - u32 *val) 140 - { 141 - return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 24); 142 - } 143 - 144 - static int ade7854_spi_read_reg_32(struct device *dev, 145 - u16 reg_address, 146 - u32 *val) 147 - { 148 - return ade7854_spi_read_reg(dev, reg_address, (u32 *)val, 32); 149 - } 150 - 151 123 static int ade7854_spi_probe(struct spi_device *spi) 152 124 { 153 125 struct ade7854_state *st; ··· 130 158 return -ENOMEM; 131 159 st = iio_priv(indio_dev); 132 160 spi_set_drvdata(spi, indio_dev); 133 - st->read_reg_8 = ade7854_spi_read_reg_8; 134 - st->read_reg_16 = ade7854_spi_read_reg_16; 135 - st->read_reg_24 = ade7854_spi_read_reg_24; 136 - st->read_reg_32 = ade7854_spi_read_reg_32; 161 + st->read_reg = ade7854_spi_read_reg; 137 162 st->write_reg = ade7854_spi_write_reg; 138 163 st->irq = spi->irq; 139 164 st->spi = spi;
+9 -9
drivers/staging/iio/meter/ade7854.c
··· 27 27 char *buf) 28 28 { 29 29 int ret; 30 - u8 val = 0; 30 + u32 val = 0; 31 31 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 32 32 struct ade7854_state *st = iio_priv(indio_dev); 33 33 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 34 34 35 - ret = st->read_reg_8(dev, this_attr->address, &val); 35 + ret = st->read_reg(dev, this_attr->address, &val, 8); 36 36 if (ret < 0) 37 37 return ret; 38 38 ··· 44 44 char *buf) 45 45 { 46 46 int ret; 47 - u16 val = 0; 47 + u32 val = 0; 48 48 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 49 49 struct ade7854_state *st = iio_priv(indio_dev); 50 50 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 51 51 52 - ret = st->read_reg_16(dev, this_attr->address, &val); 52 + ret = st->read_reg(dev, this_attr->address, &val, 16); 53 53 if (ret < 0) 54 54 return ret; 55 55 ··· 66 66 struct ade7854_state *st = iio_priv(indio_dev); 67 67 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 68 68 69 - ret = st->read_reg_24(dev, this_attr->address, &val); 69 + ret = st->read_reg(dev, this_attr->address, &val, 24); 70 70 if (ret < 0) 71 71 return ret; 72 72 ··· 83 83 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 84 84 struct ade7854_state *st = iio_priv(indio_dev); 85 85 86 - ret = st->read_reg_32(dev, this_attr->address, &val); 86 + ret = st->read_reg(dev, this_attr->address, &val, 32); 87 87 if (ret < 0) 88 88 return ret; 89 89 ··· 178 178 { 179 179 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 180 180 struct ade7854_state *st = iio_priv(indio_dev); 181 - u16 val; 181 + u32 val; 182 182 183 - st->read_reg_16(dev, ADE7854_CONFIG, &val); 183 + st->read_reg(dev, ADE7854_CONFIG, &val, 16); 184 184 val |= BIT(7); /* Software Chip Reset */ 185 185 186 186 return st->write_reg(dev, ADE7854_CONFIG, val, 16); ··· 415 415 int ret; 416 416 u32 irqen; 417 417 418 - ret = st->read_reg_32(dev, ADE7854_MASK0, &irqen); 418 + ret = st->read_reg(dev, ADE7854_MASK0, &irqen, 32); 419 419 if (ret < 0) 420 420 return ret; 421 421
+3 -4
drivers/staging/iio/meter/ade7854.h
··· 146 146 /** 147 147 * struct ade7854_state - device instance specific data 148 148 * @spi: actual spi_device 149 + * @read_reg Wrapper function for I2C and SPI read 149 150 * @write_reg Wrapper function for I2C and SPI write 150 151 * @indio_dev: industrial I/O device structure 151 152 * @buf_lock: mutex to protect tx and rx ··· 156 155 struct ade7854_state { 157 156 struct spi_device *spi; 158 157 struct i2c_client *i2c; 159 - int (*read_reg_8)(struct device *dev, u16 reg_address, u8 *val); 160 - int (*read_reg_16)(struct device *dev, u16 reg_address, u16 *val); 161 - int (*read_reg_24)(struct device *dev, u16 reg_address, u32 *val); 162 - int (*read_reg_32)(struct device *dev, u16 reg_address, u32 *val); 158 + int (*read_reg)(struct device *dev, u16 reg_address, u32 *val, 159 + int bits); 163 160 int (*write_reg)(struct device *dev, u16 reg_address, u32 val, 164 161 int bits); 165 162 int irq;