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.

dmaengine: loongson: loongson2-apb: Simplify locking with guard() and scoped_guard()

Use guard() and scoped_guard() infrastructure instead of explicitly
acquiring and releasing spinlocks to simplify the code and ensure that
all locks are released properly.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://patch.msgid.link/fb59bb25e5c4fcb84d9aa7b351285fa8d02ea8cb.1772853681.git.zhoubinbin@loongson.cn
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Binbin Zhou and committed by
Vinod Koul
9de4303f bdf1621a

+29 -33
+29 -33
drivers/dma/loongson/loongson2-apb-dma.c
··· 461 461 static void ls2x_dma_issue_pending(struct dma_chan *chan) 462 462 { 463 463 struct ls2x_dma_chan *lchan = to_ldma_chan(chan); 464 - unsigned long flags; 465 464 466 - spin_lock_irqsave(&lchan->vchan.lock, flags); 465 + guard(spinlock_irqsave)(&lchan->vchan.lock); 466 + 467 467 if (vchan_issue_pending(&lchan->vchan) && !lchan->desc) 468 468 ls2x_dma_start_transfer(lchan); 469 - spin_unlock_irqrestore(&lchan->vchan.lock, flags); 470 469 } 471 470 472 471 /* ··· 477 478 static int ls2x_dma_terminate_all(struct dma_chan *chan) 478 479 { 479 480 struct ls2x_dma_chan *lchan = to_ldma_chan(chan); 480 - unsigned long flags; 481 481 LIST_HEAD(head); 482 482 483 - spin_lock_irqsave(&lchan->vchan.lock, flags); 484 - /* Setting stop cmd */ 485 - ls2x_dma_write_cmd(lchan, LDMA_STOP); 486 - if (lchan->desc) { 487 - vchan_terminate_vdesc(&lchan->desc->vdesc); 488 - lchan->desc = NULL; 489 - } 483 + scoped_guard(spinlock_irqsave, &lchan->vchan.lock) { 484 + /* Setting stop cmd */ 485 + ls2x_dma_write_cmd(lchan, LDMA_STOP); 486 + if (lchan->desc) { 487 + vchan_terminate_vdesc(&lchan->desc->vdesc); 488 + lchan->desc = NULL; 489 + } 490 490 491 - vchan_get_all_descriptors(&lchan->vchan, &head); 492 - spin_unlock_irqrestore(&lchan->vchan.lock, flags); 491 + vchan_get_all_descriptors(&lchan->vchan, &head); 492 + } 493 493 494 494 vchan_dma_desc_free_list(&lchan->vchan, &head); 495 495 return 0; ··· 509 511 static int ls2x_dma_pause(struct dma_chan *chan) 510 512 { 511 513 struct ls2x_dma_chan *lchan = to_ldma_chan(chan); 512 - unsigned long flags; 513 514 514 - spin_lock_irqsave(&lchan->vchan.lock, flags); 515 + guard(spinlock_irqsave)(&lchan->vchan.lock); 516 + 515 517 if (lchan->desc && lchan->desc->status == DMA_IN_PROGRESS) { 516 518 ls2x_dma_write_cmd(lchan, LDMA_STOP); 517 519 lchan->desc->status = DMA_PAUSED; 518 520 } 519 - spin_unlock_irqrestore(&lchan->vchan.lock, flags); 520 521 521 522 return 0; 522 523 } ··· 523 526 static int ls2x_dma_resume(struct dma_chan *chan) 524 527 { 525 528 struct ls2x_dma_chan *lchan = to_ldma_chan(chan); 526 - unsigned long flags; 527 529 528 - spin_lock_irqsave(&lchan->vchan.lock, flags); 530 + guard(spinlock_irqsave)(&lchan->vchan.lock); 531 + 529 532 if (lchan->desc && lchan->desc->status == DMA_PAUSED) { 530 533 lchan->desc->status = DMA_IN_PROGRESS; 531 534 ls2x_dma_write_cmd(lchan, LDMA_START); 532 535 } 533 - spin_unlock_irqrestore(&lchan->vchan.lock, flags); 534 536 535 537 return 0; 536 538 } ··· 546 550 struct ls2x_dma_chan *lchan = dev_id; 547 551 struct ls2x_dma_desc *desc; 548 552 549 - spin_lock(&lchan->vchan.lock); 550 - desc = lchan->desc; 551 - if (desc) { 552 - if (desc->cyclic) { 553 - vchan_cyclic_callback(&desc->vdesc); 554 - } else { 555 - desc->status = DMA_COMPLETE; 556 - vchan_cookie_complete(&desc->vdesc); 557 - ls2x_dma_start_transfer(lchan); 558 - } 553 + scoped_guard(spinlock, &lchan->vchan.lock) { 554 + desc = lchan->desc; 555 + if (desc) { 556 + if (desc->cyclic) { 557 + vchan_cyclic_callback(&desc->vdesc); 558 + } else { 559 + desc->status = DMA_COMPLETE; 560 + vchan_cookie_complete(&desc->vdesc); 561 + ls2x_dma_start_transfer(lchan); 562 + } 559 563 560 - /* ls2x_dma_start_transfer() updates lchan->desc */ 561 - if (!lchan->desc) 562 - ls2x_dma_write_cmd(lchan, LDMA_STOP); 564 + /* ls2x_dma_start_transfer() updates lchan->desc */ 565 + if (!lchan->desc) 566 + ls2x_dma_write_cmd(lchan, LDMA_STOP); 567 + } 563 568 } 564 - spin_unlock(&lchan->vchan.lock); 565 569 566 570 return IRQ_HANDLED; 567 571 }