mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
mfd: mt6360: Use scoped variables with memory allocators to simplify error paths
Allocate the memory with scoped/cleanup.h to reduce error handling and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240707114823.9175-1-krzysztof.kozlowski@linaro.org Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
parent
691277c90c
commit
4194783812
@ -5,6 +5,7 @@
|
|||||||
* Author: Gene Chen <gene_chen@richtek.com>
|
* Author: Gene Chen <gene_chen@richtek.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/crc8.h>
|
#include <linux/crc8.h>
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
@ -404,7 +405,6 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
|
|||||||
u8 reg_addr = *(u8 *)(reg + 1);
|
u8 reg_addr = *(u8 *)(reg + 1);
|
||||||
struct i2c_client *i2c;
|
struct i2c_client *i2c;
|
||||||
bool crc_needed = false;
|
bool crc_needed = false;
|
||||||
u8 *buf;
|
|
||||||
int buf_len = MT6360_ALLOC_READ_SIZE(val_size);
|
int buf_len = MT6360_ALLOC_READ_SIZE(val_size);
|
||||||
int read_size = val_size;
|
int read_size = val_size;
|
||||||
u8 crc;
|
u8 crc;
|
||||||
@ -423,7 +423,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
|
|||||||
read_size += MT6360_CRC_CRC8_SIZE;
|
read_size += MT6360_CRC_CRC8_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = kzalloc(buf_len, GFP_KERNEL);
|
u8 *buf __free(kfree) = kzalloc(buf_len, GFP_KERNEL);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -433,24 +433,19 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
|
|||||||
ret = i2c_smbus_read_i2c_block_data(i2c, reg_addr, read_size,
|
ret = i2c_smbus_read_i2c_block_data(i2c, reg_addr, read_size,
|
||||||
buf + MT6360_CRC_PREDATA_OFFSET);
|
buf + MT6360_CRC_PREDATA_OFFSET);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
else if (ret != read_size) {
|
else if (ret != read_size)
|
||||||
ret = -EIO;
|
return -EIO;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (crc_needed) {
|
if (crc_needed) {
|
||||||
crc = crc8(ddata->crc8_tbl, buf, val_size + MT6360_CRC_PREDATA_OFFSET, 0);
|
crc = crc8(ddata->crc8_tbl, buf, val_size + MT6360_CRC_PREDATA_OFFSET, 0);
|
||||||
if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET]) {
|
if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET])
|
||||||
ret = -EIO;
|
return -EIO;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(val, buf + MT6360_CRC_PREDATA_OFFSET, val_size);
|
memcpy(val, buf + MT6360_CRC_PREDATA_OFFSET, val_size);
|
||||||
out:
|
|
||||||
kfree(buf);
|
return 0;
|
||||||
return (ret < 0) ? ret : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mt6360_regmap_write(void *context, const void *val, size_t val_size)
|
static int mt6360_regmap_write(void *context, const void *val, size_t val_size)
|
||||||
|
Loading…
Reference in New Issue
Block a user