diff options
author | Alexander Sverdlin <alexander.sverdlin@nsn.com> | 2013-10-14 12:52:23 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-03-11 01:42:21 -0400 |
commit | 6f6b9feece0066695d87ed6df5bc0d8080c0c96c (patch) | |
tree | 2bf457627d4eb0fa9a9652bd62fa6edd85f3592a /drivers/mtd/devices | |
parent | b4c233057771581698a13694ab6f33b48ce837dc (diff) |
mtd: phram: Repair multiple instances support
Commit b2a2a84d35e0f42ad26e326ec4258f6a8b8eecbe (mtd: phram: dot not crash when
built-in and passing boot param) claims to be "based on Ville Herva's similar
patch to block2mtd" (c4e7fb313771ac03dfdca26d30e8b721731c562b), but it has
missed the crucial point of the original path: all these "if(n)def MODULE".
It has broken the possibility to create several phram instances when phram is
compiled as module. The possibility to add instances via /sys writes to
/sys/module/phram/parameters/phram was also broken with mentioned patch.
Proposed patch takes the idea of original block2mtd patch to its full extent.
Assumption "This function is always called before 'init_phram()'" was also
incorrect, so removed the comment. This patch effectively reverts also
b11ec57fc6e6d4882ef01a0c09a1dde58f50492e (mtd: phram: fix section mismatch for
phram_setup).
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nsn.com>
[Brian: remove static assigment = 0]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r-- | drivers/mtd/devices/phram.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index e1f2aebaa489..2cceebfb251e 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c | |||
@@ -205,6 +205,8 @@ static inline void kill_final_newline(char *str) | |||
205 | return 1; \ | 205 | return 1; \ |
206 | } while (0) | 206 | } while (0) |
207 | 207 | ||
208 | #ifndef MODULE | ||
209 | static int phram_init_called; | ||
208 | /* | 210 | /* |
209 | * This shall contain the module parameter if any. It is of the form: | 211 | * This shall contain the module parameter if any. It is of the form: |
210 | * - phram=<device>,<address>,<size> for module case | 212 | * - phram=<device>,<address>,<size> for module case |
@@ -213,9 +215,10 @@ static inline void kill_final_newline(char *str) | |||
213 | * size. | 215 | * size. |
214 | * Example: phram.phram=rootfs,0xa0000000,512Mi | 216 | * Example: phram.phram=rootfs,0xa0000000,512Mi |
215 | */ | 217 | */ |
216 | static __initdata char phram_paramline[64 + 20 + 20]; | 218 | static char phram_paramline[64 + 20 + 20]; |
219 | #endif | ||
217 | 220 | ||
218 | static int __init phram_setup(const char *val) | 221 | static int phram_setup(const char *val) |
219 | { | 222 | { |
220 | char buf[64 + 20 + 20], *str = buf; | 223 | char buf[64 + 20 + 20], *str = buf; |
221 | char *token[3]; | 224 | char *token[3]; |
@@ -264,17 +267,36 @@ static int __init phram_setup(const char *val) | |||
264 | return ret; | 267 | return ret; |
265 | } | 268 | } |
266 | 269 | ||
267 | static int __init phram_param_call(const char *val, struct kernel_param *kp) | 270 | static int phram_param_call(const char *val, struct kernel_param *kp) |
268 | { | 271 | { |
272 | #ifdef MODULE | ||
273 | return phram_setup(val); | ||
274 | #else | ||
269 | /* | 275 | /* |
270 | * This function is always called before 'init_phram()', whether | 276 | * If more parameters are later passed in via |
271 | * built-in or module. | 277 | * /sys/module/phram/parameters/phram |
278 | * and init_phram() has already been called, | ||
279 | * we can parse the argument now. | ||
272 | */ | 280 | */ |
281 | |||
282 | if (phram_init_called) | ||
283 | return phram_setup(val); | ||
284 | |||
285 | /* | ||
286 | * During early boot stage, we only save the parameters | ||
287 | * here. We must parse them later: if the param passed | ||
288 | * from kernel boot command line, phram_param_call() is | ||
289 | * called so early that it is not possible to resolve | ||
290 | * the device (even kmalloc() fails). Defer that work to | ||
291 | * phram_setup(). | ||
292 | */ | ||
293 | |||
273 | if (strlen(val) >= sizeof(phram_paramline)) | 294 | if (strlen(val) >= sizeof(phram_paramline)) |
274 | return -ENOSPC; | 295 | return -ENOSPC; |
275 | strcpy(phram_paramline, val); | 296 | strcpy(phram_paramline, val); |
276 | 297 | ||
277 | return 0; | 298 | return 0; |
299 | #endif | ||
278 | } | 300 | } |
279 | 301 | ||
280 | module_param_call(phram, phram_param_call, NULL, NULL, 000); | 302 | module_param_call(phram, phram_param_call, NULL, NULL, 000); |
@@ -283,10 +305,15 @@ MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>\" | |||
283 | 305 | ||
284 | static int __init init_phram(void) | 306 | static int __init init_phram(void) |
285 | { | 307 | { |
308 | int ret = 0; | ||
309 | |||
310 | #ifndef MODULE | ||
286 | if (phram_paramline[0]) | 311 | if (phram_paramline[0]) |
287 | return phram_setup(phram_paramline); | 312 | ret = phram_setup(phram_paramline); |
313 | phram_init_called = 1; | ||
314 | #endif | ||
288 | 315 | ||
289 | return 0; | 316 | return ret; |
290 | } | 317 | } |
291 | 318 | ||
292 | static void __exit cleanup_phram(void) | 319 | static void __exit cleanup_phram(void) |