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

gpio: 74x164: Driver cleanup

- Removed excess "spi" field from private data.
- Removed excess check for spi_get_drvdata() in remove().
- Removed unneeded message in remove().
- Simplify error path in probe().
- Fixed warnings by scripts/checkfile.pl.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Alexander Shiyan and committed by
Linus Walleij
bcc0562c 61e73804

+16 -27
+16 -27
drivers/gpio/gpio-74x164.c
··· 20 20 #define GEN_74X164_NUMBER_GPIOS 8 21 21 22 22 struct gen_74x164_chip { 23 - struct spi_device *spi; 24 23 u8 *buffer; 25 24 struct gpio_chip gpio_chip; 26 25 struct mutex lock; ··· 33 34 34 35 static int __gen_74x164_write_config(struct gen_74x164_chip *chip) 35 36 { 37 + struct spi_device *spi = to_spi_device(chip->gpio_chip.dev); 36 38 struct spi_message message; 37 39 struct spi_transfer *msg_buf; 38 40 int i, ret = 0; ··· 54 54 * byte of the buffer will end up in the last register. 55 55 */ 56 56 for (i = chip->registers - 1; i >= 0; i--) { 57 - msg_buf[i].tx_buf = chip->buffer +i; 57 + msg_buf[i].tx_buf = chip->buffer + i; 58 58 msg_buf[i].len = sizeof(u8); 59 59 spi_message_add_tail(msg_buf + i, &message); 60 60 } 61 61 62 - ret = spi_sync(chip->spi, &message); 62 + ret = spi_sync(spi, &message); 63 63 64 64 kfree(msg_buf); 65 65 ··· 122 122 if (!chip) 123 123 return -ENOMEM; 124 124 125 - mutex_init(&chip->lock); 126 - 127 125 spi_set_drvdata(spi, chip); 128 - 129 - chip->spi = spi; 130 126 131 127 chip->gpio_chip.label = spi->modalias; 132 128 chip->gpio_chip.direction_output = gen_74x164_direction_output; ··· 130 134 chip->gpio_chip.set = gen_74x164_set_value; 131 135 chip->gpio_chip.base = -1; 132 136 133 - if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { 134 - dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); 135 - ret = -EINVAL; 136 - goto exit_destroy; 137 + if (of_property_read_u32(spi->dev.of_node, "registers-number", 138 + &chip->registers)) { 139 + dev_err(&spi->dev, 140 + "Missing registers-number property in the DT.\n"); 141 + return -EINVAL; 137 142 } 138 143 139 144 chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; 140 145 chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL); 141 - if (!chip->buffer) { 142 - ret = -ENOMEM; 143 - goto exit_destroy; 144 - } 146 + if (!chip->buffer) 147 + return -ENOMEM; 145 148 146 149 chip->gpio_chip.can_sleep = true; 147 150 chip->gpio_chip.dev = &spi->dev; 148 151 chip->gpio_chip.owner = THIS_MODULE; 152 + 153 + mutex_init(&chip->lock); 149 154 150 155 ret = __gen_74x164_write_config(chip); 151 156 if (ret) { ··· 155 158 } 156 159 157 160 ret = gpiochip_add(&chip->gpio_chip); 158 - if (ret) 159 - goto exit_destroy; 160 - 161 - return ret; 161 + if (!ret) 162 + return 0; 162 163 163 164 exit_destroy: 164 165 mutex_destroy(&chip->lock); 166 + 165 167 return ret; 166 168 } 167 169 168 170 static int gen_74x164_remove(struct spi_device *spi) 169 171 { 170 - struct gen_74x164_chip *chip; 172 + struct gen_74x164_chip *chip = spi_get_drvdata(spi); 171 173 int ret; 172 - 173 - chip = spi_get_drvdata(spi); 174 - if (chip == NULL) 175 - return -ENODEV; 176 174 177 175 ret = gpiochip_remove(&chip->gpio_chip); 178 176 if (!ret) 179 177 mutex_destroy(&chip->lock); 180 - else 181 - dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", 182 - ret); 183 178 184 179 return ret; 185 180 }