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

Configure Feed

Select the types of activity you want to include in your feed.

iio: dac: ltc2688: use the auto lock API

Make use of the cleanup API so that we can simplify some code paths.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
70fde048 7798b50e

+12 -16
+12 -16
drivers/iio/dac/ltc2688.c
··· 6 6 */ 7 7 #include <linux/bitfield.h> 8 8 #include <linux/bits.h> 9 + #include <linux/cleanup.h> 9 10 #include <linux/clk.h> 10 11 #include <linux/device.h> 11 12 #include <linux/gpio/consumer.h> ··· 209 208 code = FIELD_PREP(LTC2688_DITHER_RAW_MASK, code); 210 209 } 211 210 212 - mutex_lock(&st->lock); 211 + guard(mutex)(&st->lock); 213 212 /* select the correct input register to read from */ 214 213 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), 215 214 input << chan); 216 215 if (ret) 217 - goto out_unlock; 216 + return ret; 218 217 219 218 /* 220 219 * If in dither/toggle mode the dac should be updated by an ··· 225 224 else 226 225 reg = LTC2688_CMD_CH_CODE(chan); 227 226 228 - ret = regmap_write(st->regmap, reg, code); 229 - out_unlock: 230 - mutex_unlock(&st->lock); 231 - return ret; 227 + return regmap_write(st->regmap, reg, code); 232 228 } 233 229 234 230 static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input, ··· 234 236 struct ltc2688_chan *c = &st->channels[chan]; 235 237 int ret; 236 238 237 - mutex_lock(&st->lock); 239 + guard(mutex)(&st->lock); 238 240 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), 239 241 input << chan); 240 242 if (ret) 241 - goto out_unlock; 243 + return ret; 242 244 243 245 ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code); 244 - out_unlock: 245 - mutex_unlock(&st->lock); 246 + if (ret) 247 + return ret; 246 248 247 249 if (!c->toggle_chan && input == LTC2688_INPUT_B) 248 250 *code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code); 249 251 250 - return ret; 252 + return 0; 251 253 } 252 254 253 255 static const int ltc2688_raw_range[] = {0, 1, U16_MAX}; ··· 357 359 if (ret) 358 360 return ret; 359 361 360 - mutex_lock(&st->lock); 362 + guard(mutex)(&st->lock); 361 363 ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN, 362 364 BIT(chan->channel), en << chan->channel); 363 365 if (ret) 364 - goto out_unlock; 366 + return ret; 365 367 366 368 c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT; 367 - out_unlock: 368 - mutex_unlock(&st->lock); 369 369 370 - return ret ?: len; 370 + return len; 371 371 } 372 372 373 373 static ssize_t ltc2688_reg_bool_get(struct iio_dev *indio_dev,