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: light: veml6070: use guard to handle mutex

Simplify the mutext handling by using a guard to automate the mutex
unlocking.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://patch.msgid.link/20240929-veml6070-cleanup-v1-2-a9350341a646@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Javier Carrasco and committed by
Jonathan Cameron
fc385251 7501bff8

+8 -8
+8 -8
drivers/iio/light/veml6070.c
··· 42 42 int ret; 43 43 u8 msb, lsb; 44 44 45 - mutex_lock(&data->lock); 45 + guard(mutex)(&data->lock); 46 46 47 47 /* disable shutdown */ 48 48 ret = i2c_smbus_write_byte(data->client1, 49 49 data->config & ~VEML6070_COMMAND_SD); 50 50 if (ret < 0) 51 - goto out; 51 + return ret; 52 52 53 53 msleep(125 + 10); /* measurement takes up to 125 ms for IT 1x */ 54 54 55 55 ret = i2c_smbus_read_byte(data->client2); /* read MSB, address 0x39 */ 56 56 if (ret < 0) 57 - goto out; 57 + return ret; 58 + 58 59 msb = ret; 59 60 60 61 ret = i2c_smbus_read_byte(data->client1); /* read LSB, address 0x38 */ 61 62 if (ret < 0) 62 - goto out; 63 + return ret; 64 + 63 65 lsb = ret; 64 66 65 67 /* shutdown again */ 66 68 ret = i2c_smbus_write_byte(data->client1, data->config); 67 69 if (ret < 0) 68 - goto out; 70 + return ret; 69 71 70 72 ret = (msb << 8) | lsb; 71 73 72 - out: 73 - mutex_unlock(&data->lock); 74 - return ret; 74 + return 0; 75 75 } 76 76 77 77 static const struct iio_chan_spec veml6070_channels[] = {