1212#include <linux/init.h>
1313#include <linux/interrupt.h>
1414#include <linux/module.h>
15+ #include <linux/mutex.h>
1516#include <linux/regmap.h>
1617#include <linux/regulator/driver.h>
1718#include <linux/regulator/machine.h>
@@ -293,21 +294,24 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
293294 if (!state )
294295 return - ENOMEM ;
295296
296- mutex_init (& state -> lock );
297+ ret = devm_mutex_init (& i2c -> dev , & state -> lock );
298+ if (ret )
299+ return ret ;
300+
297301 i2c_set_clientdata (i2c , state );
298302
299303 regmap = devm_regmap_init_i2c (i2c , & attiny_regmap_config );
300304 if (IS_ERR (regmap )) {
301305 ret = PTR_ERR (regmap );
302306 dev_err (& i2c -> dev , "Failed to allocate register map: %d\n" ,
303307 ret );
304- goto error ;
308+ return ret ;
305309 }
306310
307311 ret = attiny_i2c_read (i2c , REG_ID , & data );
308312 if (ret < 0 ) {
309313 dev_err (& i2c -> dev , "Failed to read REG_ID reg: %d\n" , ret );
310- goto error ;
314+ return ret ;
311315 }
312316
313317 switch (data ) {
@@ -316,8 +320,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
316320 break ;
317321 default :
318322 dev_err (& i2c -> dev , "Unknown Atmel firmware revision: 0x%02x\n" , data );
319- ret = - ENODEV ;
320- goto error ;
323+ return - ENODEV ;
321324 }
322325
323326 regmap_write (regmap , REG_POWERON , 0 );
@@ -333,8 +336,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
333336 rdev = devm_regulator_register (& i2c -> dev , & attiny_regulator , & config );
334337 if (IS_ERR (rdev )) {
335338 dev_err (& i2c -> dev , "Failed to register ATTINY regulator\n" );
336- ret = PTR_ERR (rdev );
337- goto error ;
339+ return PTR_ERR (rdev );
338340 }
339341
340342 props .type = BACKLIGHT_RAW ;
@@ -345,10 +347,8 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
345347 bl = devm_backlight_device_register (& i2c -> dev , dev_name (& i2c -> dev ),
346348 & i2c -> dev , state , & attiny_bl ,
347349 & props );
348- if (IS_ERR (bl )) {
349- ret = PTR_ERR (bl );
350- goto error ;
351- }
350+ if (IS_ERR (bl ))
351+ return PTR_ERR (bl );
352352
353353 bl -> props .brightness = 0xff ;
354354
@@ -363,26 +363,12 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
363363 state -> gc .can_sleep = true;
364364
365365 ret = devm_gpiochip_add_data (& i2c -> dev , & state -> gc , state );
366- if (ret ) {
366+ if (ret )
367367 dev_err (& i2c -> dev , "Failed to create gpiochip: %d\n" , ret );
368- goto error ;
369- }
370-
371- return 0 ;
372-
373- error :
374- mutex_destroy (& state -> lock );
375368
376369 return ret ;
377370}
378371
379- static void attiny_i2c_remove (struct i2c_client * client )
380- {
381- struct attiny_lcd * state = i2c_get_clientdata (client );
382-
383- mutex_destroy (& state -> lock );
384- }
385-
386372static const struct of_device_id attiny_dt_ids [] = {
387373 { .compatible = "raspberrypi,7inch-touchscreen-panel-regulator" },
388374 {},
@@ -396,7 +382,6 @@ static struct i2c_driver attiny_regulator_driver = {
396382 .of_match_table = attiny_dt_ids ,
397383 },
398384 .probe = attiny_i2c_probe ,
399- .remove = attiny_i2c_remove ,
400385};
401386
402387module_i2c_driver (attiny_regulator_driver );
0 commit comments