Skip to content

Commit 626b2dd

Browse files
committed
Merge tag 'rpmsg-v5.17-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux
Pull rpmsg fixes from Bjorn Andersson: "The cdev cleanup in the rpmsg_char driver was not performed properly, resulting in unpredicable behaviour when the parent remote processor is stopped with any of the cdevs open by a client. Two patches transitions the implementation to use cdev_device_add() and cdev_del_device(), to capture the relationship between the two objects, and relocates the incorrectly placed cdev_del()" * tag 'rpmsg-v5.17-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux: rpmsg: char: Fix race between the release of rpmsg_eptdev and cdev rpmsg: char: Fix race between the release of rpmsg_ctrldev and cdev
2 parents 96b5590 + 7a534ae commit 626b2dd

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static int rpmsg_eptdev_destroy(struct device *dev, void *data)
9393
/* wake up any blocked readers */
9494
wake_up_interruptible(&eptdev->readq);
9595

96-
device_del(&eptdev->dev);
96+
cdev_device_del(&eptdev->cdev, &eptdev->dev);
9797
put_device(&eptdev->dev);
9898

9999
return 0;
@@ -336,7 +336,6 @@ static void rpmsg_eptdev_release_device(struct device *dev)
336336

337337
ida_simple_remove(&rpmsg_ept_ida, dev->id);
338338
ida_simple_remove(&rpmsg_minor_ida, MINOR(eptdev->dev.devt));
339-
cdev_del(&eptdev->cdev);
340339
kfree(eptdev);
341340
}
342341

@@ -381,19 +380,13 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev,
381380
dev->id = ret;
382381
dev_set_name(dev, "rpmsg%d", ret);
383382

384-
ret = cdev_add(&eptdev->cdev, dev->devt, 1);
383+
ret = cdev_device_add(&eptdev->cdev, &eptdev->dev);
385384
if (ret)
386385
goto free_ept_ida;
387386

388387
/* We can now rely on the release function for cleanup */
389388
dev->release = rpmsg_eptdev_release_device;
390389

391-
ret = device_add(dev);
392-
if (ret) {
393-
dev_err(dev, "device_add failed: %d\n", ret);
394-
put_device(dev);
395-
}
396-
397390
return ret;
398391

399392
free_ept_ida:
@@ -462,7 +455,6 @@ static void rpmsg_ctrldev_release_device(struct device *dev)
462455

463456
ida_simple_remove(&rpmsg_ctrl_ida, dev->id);
464457
ida_simple_remove(&rpmsg_minor_ida, MINOR(dev->devt));
465-
cdev_del(&ctrldev->cdev);
466458
kfree(ctrldev);
467459
}
468460

@@ -497,19 +489,13 @@ static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
497489
dev->id = ret;
498490
dev_set_name(&ctrldev->dev, "rpmsg_ctrl%d", ret);
499491

500-
ret = cdev_add(&ctrldev->cdev, dev->devt, 1);
492+
ret = cdev_device_add(&ctrldev->cdev, &ctrldev->dev);
501493
if (ret)
502494
goto free_ctrl_ida;
503495

504496
/* We can now rely on the release function for cleanup */
505497
dev->release = rpmsg_ctrldev_release_device;
506498

507-
ret = device_add(dev);
508-
if (ret) {
509-
dev_err(&rpdev->dev, "device_add failed: %d\n", ret);
510-
put_device(dev);
511-
}
512-
513499
dev_set_drvdata(&rpdev->dev, ctrldev);
514500

515501
return ret;
@@ -535,7 +521,7 @@ static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev)
535521
if (ret)
536522
dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret);
537523

538-
device_del(&ctrldev->dev);
524+
cdev_device_del(&ctrldev->cdev, &ctrldev->dev);
539525
put_device(&ctrldev->dev);
540526
}
541527

0 commit comments

Comments
 (0)