Skip to content

Commit e4b893b

Browse files
Wolfram Sanggregkh
authored andcommitted
mailbox: mailbox-test: initialize struct earlier
[ Upstream commit bbcf9af ] The waitqueue must be initialized before the debugfs files are created because from that time, requests from userspace can already be made. Similarily, drvdata and spinlock needs to be initialized before we request the channel, otherwise dangling irqs might run into problems like a NULL pointer exception. Fixes: 8ea4484 ("mailbox: Add generic mechanism for testing Mailbox Controllers") Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5c20929 commit e4b893b

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

drivers/mailbox/mailbox-test.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ static int mbox_test_probe(struct platform_device *pdev)
366366
if (!tdev)
367367
return -ENOMEM;
368368

369+
tdev->dev = &pdev->dev;
370+
spin_lock_init(&tdev->lock);
371+
mutex_init(&tdev->mutex);
372+
init_waitqueue_head(&tdev->waitq);
373+
platform_set_drvdata(pdev, tdev);
374+
369375
/* It's okay for MMIO to be NULL */
370376
tdev->tx_mmio = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
371377
if (PTR_ERR(tdev->tx_mmio) == -EBUSY) {
@@ -395,12 +401,6 @@ static int mbox_test_probe(struct platform_device *pdev)
395401
if (!tdev->rx_channel && (tdev->rx_mmio != tdev->tx_mmio))
396402
tdev->rx_channel = tdev->tx_channel;
397403

398-
tdev->dev = &pdev->dev;
399-
platform_set_drvdata(pdev, tdev);
400-
401-
spin_lock_init(&tdev->lock);
402-
mutex_init(&tdev->mutex);
403-
404404
if (tdev->rx_channel) {
405405
tdev->rx_buffer = devm_kzalloc(&pdev->dev,
406406
MBOX_MAX_MSG_LEN, GFP_KERNEL);
@@ -414,7 +414,6 @@ static int mbox_test_probe(struct platform_device *pdev)
414414
if (ret)
415415
goto err_free_chans;
416416

417-
init_waitqueue_head(&tdev->waitq);
418417
dev_info(&pdev->dev, "Successfully registered\n");
419418

420419
return 0;

0 commit comments

Comments
 (0)