55 * Author: Gene Chen <[email protected] > 66 */
77
8+ #include <linux/cleanup.h>
89#include <linux/crc8.h>
910#include <linux/i2c.h>
1011#include <linux/init.h>
@@ -404,7 +405,6 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
404405 u8 reg_addr = * (u8 * )(reg + 1 );
405406 struct i2c_client * i2c ;
406407 bool crc_needed = false;
407- u8 * buf ;
408408 int buf_len = MT6360_ALLOC_READ_SIZE (val_size );
409409 int read_size = val_size ;
410410 u8 crc ;
@@ -423,7 +423,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
423423 read_size += MT6360_CRC_CRC8_SIZE ;
424424 }
425425
426- buf = kzalloc (buf_len , GFP_KERNEL );
426+ u8 * buf __free ( kfree ) = kzalloc (buf_len , GFP_KERNEL );
427427 if (!buf )
428428 return - ENOMEM ;
429429
@@ -433,24 +433,19 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
433433 ret = i2c_smbus_read_i2c_block_data (i2c , reg_addr , read_size ,
434434 buf + MT6360_CRC_PREDATA_OFFSET );
435435 if (ret < 0 )
436- goto out ;
437- else if (ret != read_size ) {
438- ret = - EIO ;
439- goto out ;
440- }
436+ return ret ;
437+ else if (ret != read_size )
438+ return - EIO ;
441439
442440 if (crc_needed ) {
443441 crc = crc8 (ddata -> crc8_tbl , buf , val_size + MT6360_CRC_PREDATA_OFFSET , 0 );
444- if (crc != buf [val_size + MT6360_CRC_PREDATA_OFFSET ]) {
445- ret = - EIO ;
446- goto out ;
447- }
442+ if (crc != buf [val_size + MT6360_CRC_PREDATA_OFFSET ])
443+ return - EIO ;
448444 }
449445
450446 memcpy (val , buf + MT6360_CRC_PREDATA_OFFSET , val_size );
451- out :
452- kfree (buf );
453- return (ret < 0 ) ? ret : 0 ;
447+
448+ return 0 ;
454449}
455450
456451static int mt6360_regmap_write (void * context , const void * val , size_t val_size )
0 commit comments