Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: trigger: clean up viio_trigger_alloc()

1) Reverse the test for kmalloc() failure so we can pull everything
back one tab.
2) Use gotos for unwinding.
3) Some of the extra line breaks for the 80 character limit are no
longer needed so we can remove them.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Dan Carpenter and committed by
Jonathan Cameron
2c99f1a0 99a22f06

+33 -34
+33 -34
drivers/iio/industrialio-trigger.c
··· 518 518 static struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs) 519 519 { 520 520 struct iio_trigger *trig; 521 + int i; 522 + 521 523 trig = kzalloc(sizeof *trig, GFP_KERNEL); 522 - if (trig) { 523 - int i; 524 - trig->dev.type = &iio_trig_type; 525 - trig->dev.bus = &iio_bus_type; 526 - device_initialize(&trig->dev); 524 + if (!trig) 525 + return NULL; 527 526 528 - mutex_init(&trig->pool_lock); 529 - trig->subirq_base 530 - = irq_alloc_descs(-1, 0, 531 - CONFIG_IIO_CONSUMERS_PER_TRIGGER, 532 - 0); 533 - if (trig->subirq_base < 0) { 534 - kfree(trig); 535 - return NULL; 536 - } 527 + trig->dev.type = &iio_trig_type; 528 + trig->dev.bus = &iio_bus_type; 529 + device_initialize(&trig->dev); 537 530 538 - trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 539 - if (trig->name == NULL) { 540 - irq_free_descs(trig->subirq_base, 541 - CONFIG_IIO_CONSUMERS_PER_TRIGGER); 542 - kfree(trig); 543 - return NULL; 544 - } 545 - trig->subirq_chip.name = trig->name; 546 - trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 547 - trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; 548 - for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { 549 - irq_set_chip(trig->subirq_base + i, 550 - &trig->subirq_chip); 551 - irq_set_handler(trig->subirq_base + i, 552 - &handle_simple_irq); 553 - irq_modify_status(trig->subirq_base + i, 554 - IRQ_NOREQUEST | IRQ_NOAUTOEN, 555 - IRQ_NOPROBE); 556 - } 557 - get_device(&trig->dev); 531 + mutex_init(&trig->pool_lock); 532 + trig->subirq_base = irq_alloc_descs(-1, 0, 533 + CONFIG_IIO_CONSUMERS_PER_TRIGGER, 534 + 0); 535 + if (trig->subirq_base < 0) 536 + goto free_trig; 537 + 538 + trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 539 + if (trig->name == NULL) 540 + goto free_descs; 541 + 542 + trig->subirq_chip.name = trig->name; 543 + trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 544 + trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; 545 + for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { 546 + irq_set_chip(trig->subirq_base + i, &trig->subirq_chip); 547 + irq_set_handler(trig->subirq_base + i, &handle_simple_irq); 548 + irq_modify_status(trig->subirq_base + i, 549 + IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); 558 550 } 551 + get_device(&trig->dev); 559 552 560 553 return trig; 554 + 555 + free_descs: 556 + irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER); 557 + free_trig: 558 + kfree(trig); 559 + return NULL; 561 560 } 562 561 563 562 struct iio_trigger *iio_trigger_alloc(const char *fmt, ...)