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.

Input: stmfts - use guard notation when acquiring mutex

Guard notation simplifies code.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+31 -32
+31 -32
drivers/input/touchscreen/stmfts.c
··· 302 302 struct stmfts_data *sdata = dev; 303 303 int err; 304 304 305 - mutex_lock(&sdata->mutex); 305 + guard(mutex)(&sdata->mutex); 306 306 307 307 err = stmfts_read_events(sdata); 308 308 if (unlikely(err)) ··· 311 311 else 312 312 stmfts_parse_events(sdata); 313 313 314 - mutex_unlock(&sdata->mutex); 315 314 return IRQ_HANDLED; 316 315 } 317 316 ··· 346 347 return err; 347 348 } 348 349 349 - mutex_lock(&sdata->mutex); 350 - sdata->running = true; 350 + scoped_guard(mutex, &sdata->mutex) { 351 + sdata->running = true; 351 352 352 - if (sdata->hover_enabled) { 353 - err = i2c_smbus_write_byte(sdata->client, 354 - STMFTS_SS_HOVER_SENSE_ON); 355 - if (err) 356 - dev_warn(&sdata->client->dev, 357 - "failed to enable hover\n"); 353 + if (sdata->hover_enabled) { 354 + err = i2c_smbus_write_byte(sdata->client, 355 + STMFTS_SS_HOVER_SENSE_ON); 356 + if (err) 357 + dev_warn(&sdata->client->dev, 358 + "failed to enable hover\n"); 359 + } 358 360 } 359 - mutex_unlock(&sdata->mutex); 360 361 361 362 if (sdata->use_key) { 362 363 err = i2c_smbus_write_byte(sdata->client, ··· 380 381 dev_warn(&sdata->client->dev, 381 382 "failed to disable touchscreen: %d\n", err); 382 383 383 - mutex_lock(&sdata->mutex); 384 + scoped_guard(mutex, &sdata->mutex) { 385 + sdata->running = false; 384 386 385 - sdata->running = false; 386 - 387 - if (sdata->hover_enabled) { 388 - err = i2c_smbus_write_byte(sdata->client, 389 - STMFTS_SS_HOVER_SENSE_OFF); 390 - if (err) 391 - dev_warn(&sdata->client->dev, 392 - "failed to disable hover: %d\n", err); 387 + if (sdata->hover_enabled) { 388 + err = i2c_smbus_write_byte(sdata->client, 389 + STMFTS_SS_HOVER_SENSE_OFF); 390 + if (err) 391 + dev_warn(&sdata->client->dev, 392 + "failed to disable hover: %d\n", err); 393 + } 393 394 } 394 - mutex_unlock(&sdata->mutex); 395 395 396 396 if (sdata->use_key) { 397 397 err = i2c_smbus_write_byte(sdata->client, ··· 472 474 { 473 475 struct stmfts_data *sdata = dev_get_drvdata(dev); 474 476 unsigned long value; 475 - int err = 0; 477 + bool hover; 478 + int err; 476 479 477 480 if (kstrtoul(buf, 0, &value)) 478 481 return -EINVAL; 479 482 480 - mutex_lock(&sdata->mutex); 483 + hover = !!value; 481 484 482 - if (value && sdata->hover_enabled) 483 - goto out; 485 + guard(mutex)(&sdata->mutex); 484 486 485 - if (sdata->running) 486 - err = i2c_smbus_write_byte(sdata->client, 487 + if (hover != sdata->hover_enabled) { 488 + if (sdata->running) { 489 + err = i2c_smbus_write_byte(sdata->client, 487 490 value ? STMFTS_SS_HOVER_SENSE_ON : 488 491 STMFTS_SS_HOVER_SENSE_OFF); 492 + if (err) 493 + return err; 494 + } 489 495 490 - if (!err) 491 - sdata->hover_enabled = !!value; 492 - 493 - out: 494 - mutex_unlock(&sdata->mutex); 496 + sdata->hover_enabled = hover; 497 + } 495 498 496 499 return len; 497 500 }