Fix common bug in most nand drivers not showing a device in sysfs
Subsystems (6)
cover Fix common bug in most nand drivers not showing a device in sysfs
A comment in mtdcore.c function add_mtd_device() which is called by mtd_device_parse_register() made me wonder:
"Caller should have set dev.parent to match the physical device."
In fact this is not done by most nand drivers.
What follows is a series which fixes this.
Tested: orion and omap2
Compile-Tested: atmel, gpio, fsmc, gpmi, plat, pxa3xx, s3c2410, sh_flctl,
sharpsl, tmio, docg4, davinci, lpc32xx_mlc, lpc32xx_slc, mxc
Not tested at all (only be view, patches 19-27): bcm47, fsl_elbc, fsl_upm,
fsl_ifc, jz4740, mpc5121m, ndfc, txx9ndfmx, socrates
The overall stat is
27 files changed, 36 insertions(+), 80 deletions(-)
and it fixes 21 of these bugs.
Regards,
Alexander Holler
PATCH 1/27 mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Most nand drivers don't set a parent device for the mtd-device. The result is that information in sysfs is missing (no folder device).
Comparing the output of
git grep mtd_device_parse_register drivers/mtd/nand/
with
git grep parent drivers/mtd/nand/ | cut -f 1 | sort -u
showed that this is a very common error. Looking at some of those drivers a common pattern is visible which I put into a new inline function to reduce source code size and to avoid future similiar errors.
--- include/linux/mtd/mtd.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
include/linux/mtd/mtd.h +10 -1
@@ -23,7 +23,7 @@#include <linux/types.h> #include <linux/uio.h> #include <linux/notifier.h> -#include <linux/device.h> +#include <linux/platform_device.h> #include <mtd/mtd-abi.h>
@@ -366,6 +366,15 @@ static inline int mtd_can_have_bb(const struct mtd_info *mtd)struct mtd_partition ;struct mtd_part_parser_data ; +static inline void mtd_setup_common_members (struct mtd_info *mtd,void *priv, +struct platform_device *pdev) +{ + mtd->priv = priv; + mtd->owner = pdev->dev.driver->owner; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.driver->name; +} + extern int mtd_device_parse_register(struct mtd_info *mtd, const char * const *part_probe_types, struct mtd_part_parser_data *parser_data,
Signature · 1 line
1.8.3.2
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Quoted 12 lines · Alexander Holler
include/linux/mtd/mtd.h +1
-1@@ -23,7 +23,7 @@#include <linux/types.h> #include <linux/uio.h> #include <linux/notifier.h> -#include <linux/device.h> +#include <linux/platform_device.h> #include <mtd/mtd-abi.h>
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 370
Quoted 5 lines
include/linux/mtd/mtd.h +2
-0@@ -366,6 +366,15 @@ static inline int mtd_can_have_bb(const struct mtd_info *mtd)struct mtd_partition ;struct mtd_part_parser_data ; +static inline void mtd_setup_common_members (struct mtd_info *mtd,void *priv, +struct platform_device *pdev)
Thanks for the diligence on catching these issues, but I'm not sure this helper function is fully the correct approach here.
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 372
Quoted 2 lines
include/linux/mtd/mtd.h +2
-0+{ + mtd->priv = priv;
I don't think you should hide this one here. It will be quite obvious if a driver didn't stash its private data but tries to access it later. Are there any drivers that missed this?
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 375
Quoted 3 lines
include/linux/mtd/mtd.h +3
-0+ mtd->owner = pdev->dev.driver->owner; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.driver->name;
I think this is a little dangerous. You're potentially clobbering the name that a driver already chose here. And why did you pick to use the driver name? This gives non-unique names if there is more than one device instantiated for a driver. That's why some drivers already use the device name, not the driver name:
mtd->name = dev_name(&pev->dev);
And in fact, if any drivers are missing mtd->name, perhaps it's best to just modify the MTD registration to give them a default:
if (!mtd->name) mtd->name = dev_name(&pdev->dev);
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 376
Quoted 1 line
include/linux/mtd/mtd.h +1
-0+}
BTW, nothing in this function actually makes sense to require a platform_device, does it? And it's possible to have non-platform drivers that want to do basic MTD initialization. So (if we still keep this helper function at all), I'd recommend just a 'struct device *dev' parameter.
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 380
Quoted 4 lines
include/linux/mtd/mtd.h +1
-0+ extern int mtd_device_parse_register(struct mtd_info *mtd, const char * const *part_probe_types, struct mtd_part_parser_data *parser_data,
How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
drivers/mtd/mtdcore.c +5 -0
@@ -397,6 +397,11 @@ int add_mtd_device(struct mtd_info *mtd)if (device_register (&mtd->dev) !=0 ) goto fail_added; +if (mtd->dev.parent) + mtd->owner = mtd->dev.parent->driver->owner; +else +WARN_ON (1 ); +if (MTD_DEVT (i)) device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1,
drivers/mtd/mtdpart.c +0 -1
@@ -370,7 +370,6 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.subpage_sft = master->subpage_sft; slave->mtd.name = name; - slave->mtd.owner = master->owner; slave->mtd.backing_dev_info = master->backing_dev_info;/* NOTE: we don't arrange MTDs as a tree; it'd be error-prone
--
Brian
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Am 28.05.2014 10:43, schrieb Brian Norris:
Quoted 22 lines · Alexander Holler
Quoted 12 lines
include/linux/mtd/mtd.h +1
-1@@ -23,7 +23,7 @@#include <linux/types.h> #include <linux/uio.h> #include <linux/notifier.h> -#include <linux/device.h> +#include <linux/platform_device.h> #include <mtd/mtd-abi.h> include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 370
Quoted 5 lines
include/linux/mtd/mtd.h +2
-0@@ -366,6 +366,15 @@ static inline int mtd_can_have_bb(const struct mtd_info *mtd)struct mtd_partition ;struct mtd_part_parser_data ; +static inline void mtd_setup_common_members (struct mtd_info *mtd,void *priv, +struct platform_device *pdev)Thanks for the diligence on catching these issues, but I'm not sure this helper function is fully the correct approach here.
Quoted 6 lines
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 372
Quoted 2 lines
include/linux/mtd/mtd.h +2
-0+{ + mtd->priv = priv;I don't think you should hide this one here. It will be quite obvious if a driver didn't stash its private data but tries to access it later. Are there any drivers that missed this?
No, it just saves a line of source in all drivers and I think it fits there. I don't understand why do you think it is hidden.
Quoted 11 lines
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 375
Quoted 4 lines
include/linux/mtd/mtd.h +3
-0+ mtd->owner = pdev->dev.driver->owner; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.driver->name;I think this is a little dangerous. You're potentially clobbering the name that a driver already chose here. And why did you pick to use the driver name? This gives non-unique names if there is more than one device instantiated for a driver. That's why some drivers already use the device name, not the driver name:
Quoted 9 lines
mtd->name = dev_name(&pev->dev);And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:if (!mtd->name) mtd->name = dev_name(&pdev->dev);Quoted 1 line
include/linux/mtd/mtd.h +1
-0+}
I don't clobber any name. The name is set as default before drivers might do this. And the common pattern I've seen wasn't dev_name(foo) but the drivers name. And those drivers which do use dev_name(), still do so by overwriting the default I put into that function. But feel free to change this. I will not go again and again through the 26 drivers until all maintainers and other people are happy.
Quoted 7 lines
BTW, nothing in this function actually makes sense to require a
platform_device, does it? And it's possible to have non-platform drivers that want to do basic MTD initialization. So (if we still keep this helper function at all), I'd recommend just a 'struct device *dev' parameter.
Feel free to chgange it.
Quoted 8 lines
include/linux/mtd/mtd.h static inline int mtd_can_have_bb(const struct mtd_info *mtd) · line 380
Quoted 4 lines
include/linux/mtd/mtd.h +1
-0+ extern int mtd_device_parse_register(struct mtd_info *mtd, const char * const *part_probe_types, struct mtd_part_parser_data *parser_data,How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
Feel free to change all drivers. I like my approach with fixing 21 bugs by reducing code by 44 lines.
And it offers a common function where future similiarities can be put into too. Of course you can just add 21 lines, but that is not how I do such stuff.
And I did the patches. If you don't like them, feel free to ignore them. I'm not playing remote keyboard but I do patches like I would do them, not like some arbitrary maintainer would do them. Sorry for the harsh words.
Regards,
Alexander Holler
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Quoted 11 lines · Alexander Holler
Am 28.05.2014 10:43, schrieb Brian Norris:
Quoted 7 lines · Alexander Holler
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + mtd->priv = priv;I don't think you should hide this one here. It will be quite obvious if a driver didn't stash its private data but tries to access it later. Are there any drivers that missed this?
No, it just saves a line of source in all drivers and I think it fits there. I don't understand why do you think it is hidden.
The function name doesn't make it obvious what it's doing. So all code readers will have to follow the definition to see what it's doing. But this point is not that important, so I won't argue.
Quoted 15 lines
Quoted 15 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ mtd->owner = pdev->dev.driver->owner; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.driver->name;I think this is a little dangerous. You're potentially clobbering the name that a driver already chose here. And why did you pick to use the driver name? This gives non-unique names if there is more than one device instantiated for a driver. That's why some drivers already use the device name, not the driver name:
mtd->name = dev_name(&pev->dev);And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:
Quoted 7 lines
Quoted 4 lines
if (!mtd->name) mtd->name = dev_name(&pdev->dev);Quoted 1 line
+}
I don't clobber any name. The name is set as default before drivers might do this.
At the moment this is true, but the ordering is somewhat subtle if you don't examine the details of mtd_setup_common_members() to see that it is assigning a name. I can easily imagine some new driver in which someone does:
mtd->name = ...; [...] mtd_setup_common_members(mtd, priv, pdev);
And doesn't notice that the ordering matters.
You could make this simpler by either
(1) making mtd_setup_common_members() check for mtd->name==NULL first
(2) just move the (default) name assignment to the common MTD registration, like I suggested
Quoted 11 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ extern int mtd_device_parse_register(struct mtd_info *mtd, const char * const *part_probe_types, struct mtd_part_parser_data *parser_data,How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
Feel free to change all drivers. I like my approach with fixing 21 bugs by reducing code by 44 lines.
I appreciate the bug fixes. I am just questioning the approach. Reduced (source) code doesn't help anyone if it makes the code less maintainable. My suggestions can probably make this more maintainable, fix the same bugs, and reduce the source by a similar (albeit smaller) number of lines.
Quoted 3 lines
And it offers a common function where future similiarities can be put into too. Of course you can just add 21 lines, but that is not how I do such stuff.
I don't see how your common location helps much more than putting it in mtdcore.c like I suggested, without the extra function.
Quoted 4 lines
And I did the patches. If you don't like them, feel free to ignore them. I'm not playing remote keyboard but I do patches like I would do them, not like some arbitrary maintainer would do them. Sorry for the harsh words.
Arbitrary maintainer, eh? I'm simply suggesting that this could be accomplished in a better way. If you don't want to take part in the review process, then I have no obligation to engage either.
Regards,
Brian
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Am 28.05.2014 22:10, schrieb Brian Norris:
Quoted 10 lines · Alexander Holler
Quoted 9 lines
Am 28.05.2014 10:43, schrieb Brian Norris:
Quoted 7 lines · Alexander Holler
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + mtd->priv = priv;I don't think you should hide this one here. It will be quite obvious if a driver didn't stash its private data but tries to access it later. Are there any drivers that missed this?
Quoted 6 lines
Quoted 2 lines
No, it just saves a line of source in all drivers and I think it fits there. I don't understand why do you think it is hidden.
The function name doesn't make it obvious what it's doing. So all code readers will have to follow the definition to see what it's doing. But this point is not that important, so I won't argue.
So you think every function does hide important things? How's about C? It hides which registers are used. Maybe we should go back to assembler. But I prefer to just press ctrl-} in vim.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ mtd->owner = pdev->dev.driver->owner; + mtd->dev.parent = &pdev->dev; + mtd->name = pdev->dev.driver->name;I think this is a little dangerous. You're potentially clobbering the name that a driver already chose here. And why did you pick to use the
It's a dangerous world. And ordering sometimes matters. Feel free to post another patch where you add an if() or an if (). I don't care which style you prefer, but checkpatch would want the second one.
And as I currently don't see your argument to use the driver instead of the platform device, here's an argument why I prefer to use pdev:
someone might want to use the upper layer (here the platform device) in that silly function in the future. A very personal decision I did., but...
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
driver name? This gives non-unique names if there is more than one device instantiated for a driver. That's why some drivers already use the device name, not the driver name:
mtd->name = dev_name(&pev->dev);And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
if (!mtd->name) mtd->name = dev_name(&pdev->dev);Quoted 1 line
+}
I don't clobber any name. The name is set as default before drivers might do this.
BTW. I don't like what dev_name produces. E.g. on one box I use here devname would produce f4000000.nand instead orion_nand. So I would have to name partitons with f4000000.nand. I don't understand why someone would prefer f4000000.nand instead of orion_nand, but I accept that other people do so. I don't have to understand everything.
Quoted 41 lines
At the moment this is true, but the ordering is somewhat subtle if you don't examine the details of
mtd_setup_common_members()to see that it is assigning a name. I can easily imagine some new driver in which someone does:mtd->name = ...; [...] mtd_setup_common_members(mtd, priv, pdev);And doesn't notice that the ordering matters.
You could make this simpler by either
(1) makingmtd_setup_common_members()check for mtd->name==NULL first
(2) just move the (default) name assignment to the common MTD registration, like I suggestedQuoted 11 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ extern int mtd_device_parse_register(struct mtd_info *mtd, const char * const *part_probe_types, struct mtd_part_parser_data *parser_data,How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
Feel free to change all drivers. I like my approach with fixing 21 bugs by reducing code by 44 lines.
I appreciate the bug fixes. I am just questioning the approach. Reduced (source) code doesn't help anyone if it makes the code less maintainable. My suggestions can probably make this more maintainable, fix the same bugs, and reduce the source by a similar (albeit smaller) number of lines.
Quoted 3 lines
And it offers a common function where future similiarities can be put into too. Of course you can just add 21 lines, but that is not how I do such stuff.
I don't see how your common location helps much more than putting it in
mtdcore.clike I suggested, without the extra function.
Quoted 8 lines
Quoted 4 lines
And I did the patches. If you don't like them, feel free to ignore them. I'm not playing remote keyboard but I do patches like I would do them, not like some arbitrary maintainer would do them. Sorry for the harsh words.
Arbitrary maintainer, eh? I'm simply suggesting that this could be accomplished in a better way. If you don't want to take part in the review process, then I have no obligation to engage either.
TIMTOWTDI. Humans are different, they think different, they write different code, they see code different and they prefer different styles. And what you think is a better way, isn't one in my point of view. And I prefer to not discuss such silly things like this simple 4 line function.
I'm very sorry, but I find such discussions extremly tiresome.
If you just would have suggested that one if to prevent that someone who doesn't c&p existing code would end up with a clobbered name (which he obviously can't miss if he ever would test his new or changed driver), than I maybe would have send a v2 with that if. But all the other noise just made me to want I never had send (again) a patch to LKML. It is almost impossible to avoid such answers and it turns every patch posting into a endless story where people do want to discuss every line or even character of totally silly things.
Alexander Holler
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Quoted 10 lines · Alexander Holler
I'm very sorry, but I find such discussions extremly tiresome.
If you just would have suggested that one if to prevent that someone who doesn't c&p existing code would end up with a clobbered name (which he obviously can't miss if he ever would test his new or changed driver), than I maybe would have send a v2 with that if. But all the other noise just made me to want I never had send (again) a patch to LKML. It is almost impossible to avoid such answers and it turns every patch posting into a endless story where people do want to discuss every line or even character of totally silly things.
It would help if you brought a more open attitude to the table.
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Am 28.05.2014 23:49, schrieb Brian Norris:
Quoted 12 lines · Alexander Holler
Quoted 10 lines
I'm very sorry, but I find such discussions extremly tiresome.
If you just would have suggested that one if to prevent that someone who doesn't c&p existing code would end up with a clobbered name (which he obviously can't miss if he ever would test his new or changed driver), than I maybe would have send a v2 with that if. But all the other noise just made me to want I never had send (again) a patch to LKML. It is almost impossible to avoid such answers and it turns every patch posting into a endless story where people do want to discuss every line or even character of totally silly things.
Quoted 1 line
It would help if you brought a more open attitude to the table.
Your doesn't accept that other people do write code different than you and you want to tell me I have to bring a more open attitude to the table?
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
In reply to Alexander HollerQuoted 1 line · Alexander Holler
I'm very sorry, but I find such discussions extremly tiresome.
Why discussing then at all, just go ahead and to something else.
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Am 29.05.2014 08:17, schrieb Artem Bityutskiy:
Quoted 4 lines · Alexander Holler
Quoted 1 line
I'm very sorry, but I find such discussions extremly tiresome.
Why discussing then at all, just go ahead and to something else.
Agreed. In order to maintain psychical health it's better to not get in contact with this kindergarten.
Regards,
Alexander Holler
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
In reply to Brian NorrisQuoted 6 lines · Brian Norris
And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:if (!mtd->name) mtd->name = dev_name(&pdev->dev);
...
Quoted 9 lines
How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
drivers/mtd/mtdcore.c +0
-0
drivers/mtd/mtdcore.c int add_mtd_device(struct mtd_info *mtd) · line 404
Quoted 8 lines
drivers/mtd/mtdcore.c +5
-0@@ -397,6 +397,11 @@ int add_mtd_device(struct mtd_info *mtd)if (device_register (&mtd->dev) !=0 ) goto fail_added; +if (mtd->dev.parent) + mtd->owner = mtd->dev.parent->driver->owner; +else +WARN_ON (1 ); +
So I've picked this up now. I do largely agree with the suggested approach where the validation and default settings are done in the core code. There is a problem with this, though. There are MTD devices that call mtd_device_parse_register() in the _init() function (such as the maps drivers). These don't have a device ready to be used as parent, and they would always be throwing this warning.
So either not having a parent device is bad, or it isn't. The comment suggests it is, the existing code suggests it isn't. So we'll need to make a decision about who's right.
drivers/mtd/mtdpart.c static struct mtd_part *allocate_partition(struct mtd_info *master, · line 373
Quoted 12 lines
drivers/mtd/mtdcore.c +0
-0if (MTD_DEVT (i)) device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1,drivers/mtd/mtdpart.c +0
-1@@ -370,7 +370,6 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.subpage_sft = master->subpage_sft; slave->mtd.name = name; - slave->mtd.owner = master->owner;
What would be the purpose of removing this line? Owner is already set? Can we rely on that?
Thanks,
Frans
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Quoted 22 lines · Frans Klaver
Quoted 6 lines · Brian Norris
And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:if (!mtd->name) mtd->name = dev_name(&pdev->dev);...
Quoted 12 lines
How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
drivers/mtd/mtdcore.c +0
-0@@ -397,6 +397,11 @@ int add_mtd_device(struct mtd_info *mtd)if (device_register (&mtd->dev) !=0 ) goto fail_added;
Quoted 12 lines
drivers/mtd/mtdcore.c int add_mtd_device(struct mtd_info *mtd) · line 404
Quoted 5 lines
drivers/mtd/mtdcore.c +5
-0+if (mtd->dev.parent) + mtd->owner = mtd->dev.parent->driver->owner; +else +WARN_ON (1 ); +So I've picked this up now. I do largely agree with the suggested approach where the validation and default settings are done in the core code. There is a problem with this, though. There are MTD devices that call
mtd_device_parse_register()in the_init()function (such as the maps drivers). These don't have a device ready to be used as parent, and they would always be throwing this warning.
Yeah, I came across the same thing. I think gluebi is another example.
Quoted 3 lines
So either not having a parent device is bad, or it isn't. The comment suggests it is, the existing code suggests it isn't. So we'll need to make a decision about who's right.
I think not having a parent is not really bad. It's helpful for tracking the device hierarchy in sysfs, but it's not strictly necessary. So we should probably not do anything drastic like WARN_ON() yet.
Quoted 10 lines
Quoted 10 lines
drivers/mtd/mtdcore.c +0
-0if (MTD_DEVT (i)) device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1,drivers/mtd/mtdpart.c +0
-0@@ -370,7 +370,6 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.subpage_sft = master->subpage_sft;
Quoted 5 lines
drivers/mtd/mtdpart.c static struct mtd_part *allocate_partition(struct mtd_info *master, · line 373
Quoted 2 lines
drivers/mtd/mtdpart.c +0
-1slave->mtd.name = name; - slave->mtd.owner = master->owner;What would be the purpose of removing this line? Owner is already set? Can we rely on that?
I'm not completely sure why I wrote that, but I think the only call site for alloc_partition() is in mtd_add_partition(), which calls add_mtd_device().
Brian
Re: [PATCH 01/27] mtd: nand: introduce function to fix a common bug in most nand-drivers not showing a device in sysfs
Quoted 38 lines · Brian Norris
Quoted 22 lines · Frans Klaver
Quoted 6 lines · Brian Norris
And in fact, if any drivers are missing
mtd->name, perhaps it's best to just modify the MTD registration to give them a default:if (!mtd->name) mtd->name = dev_name(&pdev->dev);...
Quoted 12 lines
How about we rethink the "helper" approach, and instead just do validation in the core code? This would cover most of the important parts of your helper, I think:
drivers/mtd/mtdcore.c +0
-0@@ -397,6 +397,11 @@ int add_mtd_device(struct mtd_info *mtd)if (device_register (&mtd->dev) !=0 ) goto fail_added;Quoted 12 lines
drivers/mtd/mtdcore.c int add_mtd_device(struct mtd_info *mtd) · line 404
Quoted 5 lines
drivers/mtd/mtdcore.c +5
-0+if (mtd->dev.parent) + mtd->owner = mtd->dev.parent->driver->owner; +else +WARN_ON (1 ); +So I've picked this up now. I do largely agree with the suggested approach where the validation and default settings are done in the core code. There is a problem with this, though. There are MTD devices that call
mtd_device_parse_register()in the_init()function (such as the maps drivers). These don't have a device ready to be used as parent, and they would always be throwing this warning.Yeah, I came across the same thing. I think gluebi is another example.
Quoted 7 lines
Quoted 3 lines
So either not having a parent device is bad, or it isn't. The comment suggests it is, the existing code suggests it isn't. So we'll need to make a decision about who's right.
I think not having a parent is not really bad. It's helpful for tracking the device hierarchy in sysfs, but it's not strictly necessary. So we should probably not do anything drastic like
WARN_ON()yet.
OK. I'll probably add some sane defaults to add_mtd_device() and have the mtd drivers make use of that fact. Since this isn't really critical, I guess fixing the sysfs entry won't need back-porting.
Quoted 16 lines
Quoted 10 lines
Quoted 10 lines
drivers/mtd/mtdcore.c +0
-0if (MTD_DEVT (i)) device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1,drivers/mtd/mtdpart.c +0
-0@@ -370,7 +370,6 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.subpage_sft = master->subpage_sft;Quoted 5 lines
drivers/mtd/mtdpart.c static struct mtd_part *allocate_partition(struct mtd_info *master, · line 373
Quoted 2 lines
drivers/mtd/mtdpart.c +0
-1slave->mtd.name = name; - slave->mtd.owner = master->owner;What would be the purpose of removing this line? Owner is already set? Can we rely on that?
Quoted 3 lines
I'm not completely sure why I wrote that, but I think the only call site for
alloc_partition()is inmtd_add_partition(), which callsadd_mtd_device().
Alright, I'll have a brief look into that again, then.
Thanks,
Frans
PATCH 2/27 mtd: nand: orion_nand: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/orion_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/orion_nand.c +1 -4
@@ -91,6 +91,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) goto no_res; } mtd = (struct mtd_info *)(nc +1 ); +mtd_setup_common_members (mtd, nc, pdev); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {
@@ -132,9 +133,6 @@ static int __init orion_nand_probe(struct platform_device *pdev) board =dev_get_platdata (&pdev->dev); } - mtd->priv = nc; - mtd->owner =THIS_MODULE ; - nc->priv = board; nc->IO_ADDR_R = nc->IO_ADDR_W = io_base; nc->cmd_ctrl = orion_nand_cmd_ctrl;
@@ -169,7 +167,6 @@ static int __init orion_nand_probe(struct platform_device *pdev) goto no_dev; } - mtd->name ="orion_nand" ; ppdata.of_node = pdev->dev.of_node; ret =mtd_device_parse_register (mtd,NULL , &ppdata, board->parts, board->nr_parts);
Signature · 1 line
1.8.3.2
PATCH 3/27 mtd: nand: omap2: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/omap2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/omap2.c +1 -2
@@ -1598,9 +1598,8 @@ static int omap_nand_probe(struct platform_device *pdev) info->of_node = pdata->of_node; info->ecc_opt = pdata->ecc_opt; mtd = &info->mtd; - mtd->priv = &info->nand; +mtd_setup_common_members (mtd, &info->nand, pdev); mtd->name =dev_name (&pdev->dev); - mtd->owner =THIS_MODULE ; nand_chip = &info->nand; nand_chip->ecc.priv =NULL ; nand_chip->options |=NAND_SKIP_BBTSCAN ;
Signature · 1 line
1.8.3.2
PATCH 4/27 mtd: nand: atmel_nand: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/atmel_nand.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/atmel_nand.c +1 -3
@@ -1980,6 +1980,7 @@ static int atmel_nand_probe(struct platform_device *pdev) host->io_phys = (dma_addr_t )mem->start; mtd = &host->mtd; +mtd_setup_common_members (mtd, nand_chip, pdev); nand_chip = &host->nand_chip; host->dev = &pdev->dev;if (IS_ENABLED (CONFIG_OF ) && pdev->dev.of_node) {
@@ -1993,8 +1994,6 @@ static int atmel_nand_probe(struct platform_device *pdev) } nand_chip->priv = host;/* link the private data structures */ - mtd->priv = nand_chip; - mtd->owner =THIS_MODULE ;/* Set address of NAND IO lines */ nand_chip->IO_ADDR_R = host->io_base;
@@ -2124,7 +2123,6 @@ static int atmel_nand_probe(struct platform_device *pdev) goto err_scan_tail; } - mtd->name ="atmel_nand" ; ppdata.of_node = pdev->dev.of_node; res =mtd_device_parse_register (mtd,NULL , &ppdata, host->board.parts, host->board.num_parts);
Signature · 1 line
1.8.3.2
PATCH 5/27 mtd: nand: gpio: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/gpio.c +1 -3
@@ -272,9 +272,7 @@ static int gpio_nand_probe(struct platform_device *pdev) chip->chip_delay = gpiomtd->plat.chip_delay; chip->cmd_ctrl = gpio_nand_cmd_ctrl; - gpiomtd->mtd_info.priv = chip; - gpiomtd->mtd_info.owner =THIS_MODULE ; - +mtd_setup_common_members (&gpiomtd->mtd_info, chip, pdev);platform_set_drvdata (pdev, gpiomtd);if (gpio_is_valid (gpiomtd->plat.gpio_nwp))
Signature · 1 line
1.8.3.2
PATCH 6/27 mtd: nand: fsmc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/fsmc_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/fsmc_nand.c +1 -2
@@ -1009,10 +1009,9 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)/* Link all private pointers */ mtd = &host->mtd; nand = &host->nand; - mtd->priv = nand; +mtd_setup_common_members (mtd, nand, pdev); nand->priv = host; - host->mtd.owner =THIS_MODULE ; nand->IO_ADDR_R = host->data_va; nand->IO_ADDR_W = host->data_va; nand->cmd_ctrl = fsmc_cmd_ctrl;
Signature · 1 line
1.8.3.2
PATCH 7/27 mtd: nand: gpmi: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1 -5
@@ -1682,11 +1682,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)/* init current chip */ this->current_chip =-1 ; -/* init the MTD data structures */ - mtd->priv = chip; - mtd->name ="gpmi-nand" ; - mtd->owner =THIS_MODULE ; -/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */ chip->priv = this; chip->select_chip = gpmi_select_chip;
@@ -1791,6 +1786,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)if (ret) goto exit_nfc_init; +mtd_setup_common_members (&this->mtd, &this->nand, pdev); ret =gpmi_nand_init (this);if (ret) goto exit_nfc_init;
Signature · 1 line
1.8.3.2
PATCH 8/27 mtd: nand: plat: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/plat_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/plat_nand.c +1 -2
@@ -60,8 +60,7 @@ static int plat_nand_probe(struct platform_device *pdev)return PTR_ERR (data->io_base); data->chip.priv = &data; - data->mtd.priv = &data->chip; - data->mtd.owner =THIS_MODULE ; +mtd_setup_common_members (&data->mtd, &data->chip, pdev); data->mtd.name =dev_name (&pdev->dev); data->chip.IO_ADDR_R = data->io_base;
Signature · 1 line
1.8.3.2
PATCH 9/27 mtd: nand: pxa3xx: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/pxa3xx_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +1 -2
@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev); chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;
Signature · 1 line
1.8.3.2
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Tue, 27 May 2014 00:12:34 +0200 от Alexander Holler <[email protected]>:
Quoted 14 lines
Fix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
Signed-off-by Alexander Holler <[email protected]>--- drivers/mtd/nand/pxa3xx_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/mtd/nand/pxa3xx_nand.c +0
-0
drivers/mtd/nand/pxa3xx_nand.c static int alloc_nand_resource(struct platform_device *pdev) · line 1590
Quoted 9 lines
drivers/mtd/nand/pxa3xx_nand.c +1
-2@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev); chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;
Should we add "driver.owner = THIS_MODULE" field for struct platform_driver in this case?
---
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Am 27.05.2014 05:12, schrieb Alexander Shiyan:
Quoted 21 lines
Tue, 27 May 2014 00:12:34 +0200 от Alexander Holler <[email protected]>:
Quoted 20 lines
Fix a common error in nand-drivers which do not set up a parent devicefor the mtd-device by using a new inline function.
Signed-off-by Alexander Holler <[email protected]>--- drivers/mtd/nand/pxa3xx_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/mtd/nand/pxa3xx_nand.c +1
-2@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev);
Quoted 5 lines
drivers/mtd/nand/pxa3xx_nand.c static int alloc_nand_resource(struct platform_device *pdev)
Quoted 3 lines
drivers/mtd/nand/pxa3xx_nand.c +0
-1chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc; --Should we add "driver.owner =
THIS_MODULE" field for structplatform_driverin this case?
Yes. I assumed all drivers/modules already had an owner. I will check them all and will send a v2 for those which don't have one. I wonder what this field is used for if it works without. ;)
Regards,
Alexander Holler
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Quoted 6 lines · Alexander Holler
Am 27.05.2014 05:12, schrieb Alexander Shiyan:
Quoted 1 line
Should we add "driver.owner =
THIS_MODULE" field for structplatform_driverin this case?Yes. I assumed all
drivers/modulesalready had an owner. I will check them all and will send a v2 for those which don't have one. I wonder what this field is used for if it works without. ;)
Looks like the mtd->owner essentially filters down to a try_module_get() (called in the get_mtd_device() API) which ensures that MTD users (e.g., mtdblock, UBI, etc.) hold a refcount on the driver module. If the owner is not set properly by a driver, then try_module_get() just does a silent no-op, so the user is none the wiser... until they try to rmmod their MTD driver while it's being used by UBI/UBIFS!
Regards,
Brian
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
In reply to Alexander ShiyanPicking on this old thread...
Quoted 12 lines · Alexander Shiyan
Quoted 12 lines
drivers/mtd/nand/pxa3xx_nand.c +1
-2@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev);
Quoted 6 lines
drivers/mtd/nand/pxa3xx_nand.c static int alloc_nand_resource(struct platform_device *pdev) · line 1590
Quoted 3 lines
drivers/mtd/nand/pxa3xx_nand.c +0
-0chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;Should we add "driver.owner =
THIS_MODULE" field for structplatform_driverin this case?
As far as I can see, for platform drivers, the owner of the driver is fixed to THIS_MODULE in __platform_driver_register().
If there's anything left to fix for this driver, please let me know.
Thanks,
Signature · 3 lines
Ezequiel García, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Quoted 22 lines · Ezequiel Garcia
Picking on this old thread...
Quoted 12 lines · Alexander Shiyan
Quoted 12 lines
drivers/mtd/nand/pxa3xx_nand.c +1
-2@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev);Quoted 6 lines
drivers/mtd/nand/pxa3xx_nand.c static int alloc_nand_resource(struct platform_device *pdev) · line 1590
Quoted 3 lines
drivers/mtd/nand/pxa3xx_nand.c +0
-0chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;Should we add "driver.owner =
THIS_MODULE" field for structplatform_driverin this case?
Quoted 2 lines
As far as I can see, for platform drivers, the owner of the driver is fixed to
THIS_MODULEin__platform_driver_register().
Looks like it. So any driver using module_platform_driver() or platform_driver_register() and also initializes platform_driver.driver.owner is just being redundant.
Maybe another "cleanup" project for Jingoo Han? ;)
Quoted 1 line
If there's anything left to fix for this driver, please let me know.
pxa3xx_nand is still missing a parent for its MTD's (mtd->dev.parent). I have a follow-up patch queued up locally that I need to send out sometime.
Brian
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Quoted 8 lines · Brian Norris
Quoted 1 line · Ezequiel Garcia
If there's anything left to fix for this driver, please let me know.
pxa3xx_nandis still missing a parent for its MTD's (mtd->dev.parent). I have a follow-up patch queued up locally that I need to send out sometime.
Maybe we can trade... you provide the reason for such parent, and I'll cook a patch in exchange :)
Signature · 3 lines
Ezequiel García, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
Re: [PATCH 09/27] mtd: nand: pxa3xx: show device structure in sysfs
Am 08.08.2014 20:11, schrieb Ezequiel Garcia:
Quoted 5 lines · Brian Norris
Quoted 4 lines · Ezequiel Garcia
Quoted 2 lines
If there's anything left to fix for this driver, please let me know.
Quoted 7 lines
Quoted 4 lines
pxa3xx_nandis still missing a parent for its MTD's (mtd->dev.parent). I have a follow-up patch queued up locally that I need to send out sometime.Maybe we can trade... you provide the reason for such parent, and I'll cook a patch in exchange :)
Just read the subject.and the introductory mail to the simple 20+ pathches I wasted my time with.
Regards,
Alexander Holler
PATCH 10/27 mtd: nand: s3c2410: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/s3c2410.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/s3c2410.c +1 -2
@@ -831,8 +831,6 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info, chip->IO_ADDR_R = chip->IO_ADDR_W; nmtd->info = info; - nmtd->mtd.priv = chip; - nmtd->mtd.owner =THIS_MODULE ; nmtd->set = set;#ifdef CONFIG_MTD_NAND_S3C2410_HWECC
@@ -1018,6 +1016,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)pr_debug ("initialising set %d (%p, info %p)\n" , setno, nmtd, info); +mtd_setup_common_members (&nmtd->mtd, &nmtd->chip, pdev);s3c2410_nand_init_chip (info, nmtd, sets); nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
Signature · 1 line
1.8.3.2
PATCH 11/27 mtd: nand: sh_flctl: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/sh_flctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/sh_flctl.c +1 -1
@@ -1124,7 +1124,7 @@ static int flctl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, flctl); flctl_mtd = &flctl->mtd; nand = &flctl->chip; - flctl_mtd->priv = nand; +mtd_setup_common_members (flctl_mtd, nand, pdev); flctl->pdev = pdev; flctl->hwecc = pdata->has_hwecc; flctl->holden = pdata->use_holden;
Signature · 1 line
1.8.3.2
PATCH 12/27 mtd: nand: sharpsl: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/sharpsl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/mtd/nand/sharpsl.c +1 -6
@@ -142,10 +142,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)/* Get pointer to private data */ this = (struct nand_chip *)(&sharpsl->chip); -/* Link the private data with the MTD structure */ - sharpsl->mtd.priv = this; - sharpsl->mtd.owner =THIS_MODULE ; - +mtd_setup_common_members (&sharpsl->mtd, this, pdev);platform_set_drvdata (pdev, sharpsl);/*
@@ -178,8 +175,6 @@ static int sharpsl_nand_probe(struct platform_device *pdev) goto err_scan;/* Register the partitions */ - sharpsl->mtd.name ="sharpsl-nand" ; - err =mtd_device_parse_register (&sharpsl->mtd,NULL ,NULL , data->partitions, data->nr_partitions);if (err)
Signature · 1 line
1.8.3.2
PATCH 13/27 mtd: nand: tmio: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/tmio_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/tmio_nand.c +1 -2
@@ -380,8 +380,7 @@ static int tmio_probe(struct platform_device *dev)platform_set_drvdata (dev, tmio); mtd = &tmio->mtd; nand_chip = &tmio->chip; - mtd->priv = nand_chip; - mtd->name ="tmio-nand" ; +mtd_setup_common_members (mtd, nand_chip, dev); tmio->ccr =devm_ioremap (&dev->dev, ccr->start,resource_size (ccr));if (!tmio->ccr)
Signature · 1 line
1.8.3.2
PATCH 14/27 mtd: nand: docg4: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/docg4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/docg4.c +1 -2
@@ -1312,9 +1312,8 @@ static int __init probe_docg4(struct platform_device *pdev) } nand = (struct nand_chip *) (mtd +1 ); doc = (struct docg4_priv *) (nand +1 ); - mtd->priv = nand; +mtd_setup_common_members (mtd, nand, pdev); nand->priv = doc; - mtd->owner =THIS_MODULE ; doc->virtadr = virtadr; doc->dev = dev;
Signature · 1 line
1.8.3.2
PATCH 15/27 mtd: nand: davinci: use mtd_setup_common_members()
In reply to Alexander HollerUse the new common function mtd_setup_common_members()
--- drivers/mtd/nand/davinci_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/davinci_nand.c +1 -4
@@ -656,11 +656,8 @@ static int nand_davinci_probe(struct platform_device *pdev) info->base = base; info->vaddr = vaddr; - info->mtd.priv = &info->chip; +mtd_setup_common_members (&info->mtd, &info->chip, pdev); info->mtd.name =dev_name (&pdev->dev); - info->mtd.owner =THIS_MODULE ; - - info->mtd.dev.parent = &pdev->dev; info->chip.IO_ADDR_R = vaddr; info->chip.IO_ADDR_W = vaddr;
Signature · 1 line
1.8.3.2
PATCH 16/27 mtd: nand: lpc32xx_mlc: use mtd_setup_common_members()
In reply to Alexander HollerUse the new common function mtd_setup_common_members()
--- drivers/mtd/nand/lpc32xx_mlc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/mtd/nand/lpc32xx_mlc.c +1 -5
@@ -681,9 +681,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) host->pdata =dev_get_platdata (&pdev->dev); nand_chip->priv = host;/* link the private data structures */ - mtd->priv = nand_chip; - mtd->owner =THIS_MODULE ; - mtd->dev.parent = &pdev->dev; +mtd_setup_common_members (mtd, nand_chip, pdev);/* Get NAND clock */ host->clk =clk_get (&pdev->dev,NULL );
@@ -790,8 +788,6 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) goto err_exit4; } - mtd->name =DRV_NAME ; - ppdata.of_node = pdev->dev.of_node; res =mtd_device_parse_register (mtd,NULL , &ppdata, host->ncfg->parts, host->ncfg->num_parts);
Signature · 1 line
1.8.3.2
PATCH 17/27 mtd: nand: lpc32xx_slc: use mtd_setup_common_members()
In reply to Alexander HollerUse the new common function mtd_setup_common_members()
--- drivers/mtd/nand/lpc32xx_slc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/lpc32xx_slc.c +1 -3
@@ -799,9 +799,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev) mtd = &host->mtd; chip = &host->nand_chip; chip->priv = host; - mtd->priv = chip; - mtd->owner =THIS_MODULE ; - mtd->dev.parent = &pdev->dev; +mtd_setup_common_members (mtd, chip, pdev);/* Get NAND clock */ host->clk =devm_clk_get (&pdev->dev,NULL );
Signature · 1 line
1.8.3.2
PATCH 18/27 mtd: nand: mxc: use mtd_setup_common_members()
In reply to Alexander HollerUse the new common function mtd_setup_common_members()
--- drivers/mtd/nand/mxc_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/mxc_nand.c +1 -4
@@ -1413,10 +1413,7 @@ static int mxcnd_probe(struct platform_device *pdev)/* structures must be linked */ this = &host->nand; mtd = &host->mtd; - mtd->priv = this; - mtd->owner =THIS_MODULE ; - mtd->dev.parent = &pdev->dev; - mtd->name =DRIVER_NAME ; +mtd_setup_common_members (mtd, this, pdev);/* 50 us command delay time */ this->chip_delay =5 ;
Signature · 1 line
1.8.3.2
PATCH 19/27 mtd: nand: bcm47: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/bcm47xxnflash/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/nand/bcm47xxnflash/main.c +1 -2
@@ -34,8 +34,7 @@ static int bcm47xxnflash_probe(struct platform_device *pdev)return -ENOMEM ; b47n->nand_chip.priv = b47n; - b47n->mtd.owner =THIS_MODULE ; - b47n->mtd.priv = &b47n->nand_chip;/* Required */ +mtd_setup_common_members (&b47n->mtd, &b47n->nand_chip, pdev); b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);if (b47n->cc->core->bus->chipinfo.id ==BCMA_CHIP_ID_BCM4706 ) {
Signature · 1 line
1.8.3.2
PATCH 20/27 mtd: nand: fsl_elbc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/fsl_elbc_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/fsl_elbc_nand.c +1 -4
@@ -732,10 +732,6 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)dev_dbg (priv->dev,"eLBC Set Information for bank %d\n" , priv->bank); -/* Fill in fsl_elbc_mtd structure */ - priv->mtd.priv = chip; - priv->mtd.owner =THIS_MODULE ; -/* set timeout to maximum */ priv->fmr =15 <<FMR_CWTO_SHIFT ;if (in_be32 (&lbc->bank[priv->bank].or) &OR_FCM_PGS )
@@ -873,6 +869,7 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev) goto err; } +mtd_setup_common_members (&priv->mtd, &priv->chip, pdev); priv->mtd.name =kasprintf (GFP_KERNEL ,"%llx.flash" , (u64 )res.start);if (!priv->mtd.name) { ret = -ENOMEM ;
Signature · 1 line
1.8.3.2
PATCH 21/27 mtd: nand: fsl_upm: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/fsl_upm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/fsl_upm.c +1 -3
@@ -175,9 +175,6 @@ static int fun_chip_init(struct fsl_upm_nand *fun,if (fun->rnb_gpio[0 ] >=0 ) fun->chip.dev_ready = fun_chip_ready; - fun->mtd.priv = &fun->chip; - fun->mtd.owner =THIS_MODULE ; - flash_np =of_get_next_child (upm_np,NULL );if (!flash_np)return -ENODEV ;
@@ -300,6 +297,7 @@ static int fun_probe(struct platform_device *ofdev) fun->dev = &ofdev->dev; fun->last_ctrl =NAND_CLE ; +mtd_setup_common_members (&fun->mtd, &fun->chip, ofdev); ret =fun_chip_init (fun, ofdev->dev.of_node, &io_res);if (ret) goto err2;
Signature · 1 line
1.8.3.2
PATCH 22/27 mtd: nand: fsl_ifc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/fsl_ifc_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/fsl_ifc_nand.c +1 -4
@@ -874,10 +874,6 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)struct nand_ecclayout *layout;u32 csor, ver; -/* Fill in fsl_ifc_mtd structure */ - priv->mtd.priv = chip; - priv->mtd.owner =THIS_MODULE ; -/* fill in nand_chip structure */ /* set up function call table */ if ((ioread32be (&ifc->cspr_cs[priv->bank].cspr)) &CSPR_PORT_SIZE_16 )
@@ -1099,6 +1095,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)IFC_NAND_EVTER_INTR_FTOERIR_EN |IFC_NAND_EVTER_INTR_WPERIR_EN , &ifc->ifc_nand.nand_evter_intr_en); +mtd_setup_common_members (&priv->mtd, &priv->chip, dev); priv->mtd.name =kasprintf (GFP_KERNEL ,"%llx.flash" , (u64 )res.start);if (!priv->mtd.name) { ret = -ENOMEM ;
Signature · 1 line
1.8.3.2
PATCH 23/27 mtd: nand: jz4740: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/jz4740_nand.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/jz4740_nand.c +1 -3
@@ -435,9 +435,7 @@ static int jz_nand_probe(struct platform_device *pdev) mtd = &nand->mtd; chip = &nand->chip; - mtd->priv = chip; - mtd->owner =THIS_MODULE ; - mtd->name ="jz4740-nand" ; +mtd_setup_common_members (mtd, chip, pdev); chip->ecc.hwctl = jz_nand_hwctl; chip->ecc.calculate = jz_nand_calculate_ecc_rs;
Signature · 1 line
1.8.3.2
PATCH 24/27 mtd: nand: mpc5121_nfc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/mpc5121_nfc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/mpc5121_nfc.c +1 -1
@@ -657,8 +657,8 @@ static int mpc5121_nfc_probe(struct platform_device *op) mtd = &prv->mtd; chip = &prv->chip; +mtd_setup_common_members (mtd, chip, op); - mtd->priv = chip; chip->priv = prv; prv->dev = dev;
Signature · 1 line
1.8.3.2
PATCH 25/27 mtd: nand: ndfc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/ndfc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/ndfc.c +1 -3
@@ -170,9 +170,6 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc, chip->ecc.strength =1 ; chip->priv = ndfc; - ndfc->mtd.priv = chip; - ndfc->mtd.owner =THIS_MODULE ; - flash_np =of_get_next_child (node,NULL );if (!flash_np)return -ENODEV ;
@@ -248,6 +245,7 @@ static int ndfc_probe(struct platform_device *ofdev)out_be32 (ndfc->ndfcbase + offset,be32_to_cpup (reg)); } +mtd_setup_common_members (&ndfc->mtd, &ndfc->chip, ofdev); err =ndfc_chip_init (ndfc, ofdev->dev.of_node);if (err) {iounmap (ndfc->ndfcbase);
Signature · 1 line
1.8.3.2
PATCH 26/27 mtd: nand: txx9ndfmc: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
--- drivers/mtd/nand/txx9ndfmc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/nand/txx9ndfmc.c +1 -3
@@ -323,9 +323,7 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)continue ; chip = &txx9_priv->chip; mtd = &txx9_priv->mtd; - mtd->owner =THIS_MODULE ; - - mtd->priv = chip; +mtd_setup_common_members (mtd, chip, dev); chip->read_byte = txx9ndfmc_read_byte; chip->read_buf = txx9ndfmc_read_buf;
Signature · 1 line
1.8.3.2
PATCH 27/27 mtd: nand: socrates: use mtd_setup_common_members()
In reply to Alexander HollerUse the new common function mtd_setup_common_members().
--- drivers/mtd/nand/socrates_nand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/socrates_nand.c +1 -4
@@ -165,10 +165,7 @@ static int socrates_nand_probe(struct platform_device *ofdev) host->dev = &ofdev->dev; nand_chip->priv = host;/* link the private data structures */ - mtd->priv = nand_chip; - mtd->name ="socrates_nand" ; - mtd->owner =THIS_MODULE ; - mtd->dev.parent = &ofdev->dev; +mtd_setup_common_members (mtd, nand_chip, ofdev); ppdata.of_node = ofdev->dev.of_node;/*should never be accessed directly */
Signature · 1 line
1.8.3.2
PATCH v2 7/27 mtd: nand: gpmi: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
---
Changes to v1: add owner to module
drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +2 -5
@@ -1682,11 +1682,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)/* init current chip */ this->current_chip =-1 ; -/* init the MTD data structures */ - mtd->priv = chip; - mtd->name ="gpmi-nand" ; - mtd->owner =THIS_MODULE ; -/* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */ chip->priv = this; chip->select_chip = gpmi_select_chip;
@@ -1791,6 +1786,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)if (ret) goto exit_nfc_init; +mtd_setup_common_members (&this->mtd, &this->nand, pdev); ret =gpmi_nand_init (this);if (ret) goto exit_nfc_init;
@@ -1819,6 +1815,7 @@ static int gpmi_nand_remove(struct platform_device *pdev)static struct platform_driver gpmi_nand_driver = { .driver = { .name ="gpmi-nand" , + .owner =THIS_MODULE , .of_match_table = gpmi_nand_id_table, }, .probe = gpmi_nand_probe,
Signature · 1 line
1.8.3.2
PATCH v2 9/27 mtd: nand: pxa3xx: show device structure in sysfs
In reply to Alexander HollerFix a common error in nand-drivers which do not set up a parent device for the mtd-device by using a new inline function.
---
Changes to v1: add owner to module
drivers/mtd/nand/pxa3xx_nand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +2 -2
@@ -1584,8 +1584,7 @@ static int alloc_nand_resource(struct platform_device *pdev) host->mtd = mtd; host->cs = cs; host->info_data = info; - mtd->priv = host; - mtd->owner =THIS_MODULE ; +mtd_setup_common_members (mtd, host, pdev); chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;
@@ -1862,6 +1861,7 @@ static int pxa3xx_nand_resume(struct platform_device *pdev)static struct platform_driver pxa3xx_nand_driver = { .driver = { .name ="pxa3xx-nand" , + .owner =THIS_MODULE , .of_match_table = pxa3xx_nand_dt_ids, }, .probe = pxa3xx_nand_probe,
Signature · 1 line
1.8.3.2
Hello,
I wonder if anyone else will fix this in a maintainer-approved style which doesn't use these evil leftovers from C666 called functions.
Or will the sysfs for most NAND drivers be knowingly broken forever?
Regards,
Alexander Holler
Am 27.05.2014 00:12, schrieb Alexander Holler:
Quoted 31 lines
A comment in
mtdcore.cfunctionadd_mtd_device()which is called bymtd_device_parse_register()made me wonder:"Caller should have set dev.parent to match the physical device."
In fact this is not done by most nand drivers.
What follows is a series which fixes this.
Tested: orion and omap2
Compile-Tested: atmel, gpio, fsmc, gpmi, plat, pxa3xx, s3c2410,sh_flctl,
sharpsl, tmio, docg4, davinci,lpc32xx_mlc,lpc32xx_slc, mxc
Not tested at all (only be view, patches 19-27): bcm47,fsl_elbc,fsl_upm,fsl_ifc, jz4740, mpc5121m, ndfc, txx9ndfmx, socratesThe overall stat is
27 files changed, 36 insertions(+), 80 deletions(-)and it fixes 21 of these bugs.
Regards,
Alexander Holler
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Am 16.10.2014 08:37, schrieb Alexander Holler:
Quoted 6 lines
Hello,
I wonder if anyone else will fix this in a maintainer-approved style which doesn't use these evil leftovers from C666 called functions.
Or will the sysfs for most NAND drivers be knowingly broken forever?
To explain that a bit more:
1. The reason I had to write 27 patches instead of just one is that such a function didn't exist. Therefor I've implemented one.
2. I was kind to write 27 patches to fix that silly bug.
3. I'm no fool and I will NOT write n * 21 patches in order to brutforce some maintainers prefered style.
Quoted 40 lines
Regards,
Alexander Holler
Am 27.05.2014 00:12, schrieb Alexander Holler:
Quoted 33 lines
A comment in
mtdcore.cfunctionadd_mtd_device()which is called bymtd_device_parse_register()made me wonder:"Caller should have set dev.parent to match the physical device."
In fact this is not done by most nand drivers.
What follows is a series which fixes this.
Tested: orion and omap2
Compile-Tested: atmel, gpio, fsmc, gpmi, plat, pxa3xx, s3c2410,sh_flctl,
sharpsl, tmio, docg4, davinci,lpc32xx_mlc,lpc32xx_slc, mxc
Not tested at all (only be view, patches 19-27): bcm47,fsl_elbc,fsl_upm,fsl_ifc, jz4740, mpc5121m, ndfc, txx9ndfmx, socratesThe overall stat is
27 files changed, 36 insertions(+), 80 deletions(-)and it fixes 21 of these bugs.
Regards,
Alexander Holler
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 3 lines · Alexander Holler
I wonder if anyone else will fix this in a maintainer-approved style which doesn't use these evil leftovers from C666 called functions.
I'll pick this up then.
Still interested in following progress?
Frans
Am 17.10.2014 um 12:53 schrieb Frans Klaver:
Quoted 6 lines · Alexander Holler
Quoted 3 lines
I wonder if anyone else will fix this in a maintainer-approved style which doesn't use these evil leftovers from C666 called functions.
I'll pick this up then.
Thanks.
Quoted 2 lines
Still interested in following progress?
As you wish. It's such a simple patch, that I think every word about it is almost a waste of time. I assume the result will be just 21 one-line-patches anyway, missing the chance to avoid similiar silly patch series in the future by creating a common function (which even reduces code size over all).
I've originally just did it because I've assumed any maintainer would just wave it through not seeing a chance for big discussions.
So, if you like, just add my Signed-off-by too, there isn't really much one could do wrong. ;)
Thanks again,
Alexander Holler
Quoted 3 lines · Alexander Holler
I assume the result will be just 21 one-line-patches anyway, missing the chance to avoid similiar silly patch series in the future by creating a common function (which even reduces code size over all).
That's to be expected, yes. A single patch may even be defensible. I share your concern that it's easier to get it wrong than it is to get it right, though.
Quoted 2 lines
So, if you like, just add my Signed-off-by too, there isn't really much one could do wrong. ;)
Sure.
Frans