提交 215a02fd 编写于 作者: B Brian Norris

mtd: grab a reference to the MTD of_node before registering it

We now stick the device node representing the current MTD (if any) into
sysfs, so let's make sure we have a reference to it before doing that.
Suggested-by: NBoris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
Reviewed-by: NBoris Brezillon <boris.brezillon@free-electrons.com>
上级 44ec23c9
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/of.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
...@@ -454,6 +455,7 @@ int add_mtd_device(struct mtd_info *mtd) ...@@ -454,6 +455,7 @@ int add_mtd_device(struct mtd_info *mtd)
mtd->dev.devt = MTD_DEVT(i); mtd->dev.devt = MTD_DEVT(i);
dev_set_name(&mtd->dev, "mtd%d", i); dev_set_name(&mtd->dev, "mtd%d", i);
dev_set_drvdata(&mtd->dev, mtd); dev_set_drvdata(&mtd->dev, mtd);
of_node_get(mtd_get_of_node(mtd));
error = device_register(&mtd->dev); error = device_register(&mtd->dev);
if (error) if (error)
goto fail_added; goto fail_added;
...@@ -476,6 +478,7 @@ int add_mtd_device(struct mtd_info *mtd) ...@@ -476,6 +478,7 @@ int add_mtd_device(struct mtd_info *mtd)
return 0; return 0;
fail_added: fail_added:
of_node_put(mtd_get_of_node(mtd));
idr_remove(&mtd_idr, i); idr_remove(&mtd_idr, i);
fail_locked: fail_locked:
mutex_unlock(&mtd_table_mutex); mutex_unlock(&mtd_table_mutex);
...@@ -517,6 +520,7 @@ int del_mtd_device(struct mtd_info *mtd) ...@@ -517,6 +520,7 @@ int del_mtd_device(struct mtd_info *mtd)
device_unregister(&mtd->dev); device_unregister(&mtd->dev);
idr_remove(&mtd_idr, mtd->index); idr_remove(&mtd_idr, mtd->index);
of_node_put(mtd_get_of_node(mtd));
module_put(THIS_MODULE); module_put(THIS_MODULE);
ret = 0; ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册