From: Eduardo Valentin on 10 May 2010 10:30 Hello again, On Mon, May 10, 2010 at 01:13:00PM +0200, ext Paul Mundt wrote: > On Mon, May 10, 2010 at 01:37:34PM +0300, Eduardo Valentin wrote: > > + */ > > +#include <linux/fs.h> > > +#include <linux/init.h> > > +#include <linux/proc_fs.h> > > +#include <linux/seq_file.h> > > + > > +extern const struct seq_operations socinfo_op; > > This doesn't look promising.. > > > +static int socinfo_open(struct inode *inode, struct file *file) > > +{ > > + return seq_open(file, &socinfo_op); > > +} > > + > If you use single_open() .. > > > +static const struct file_operations proc_socinfo_operations = { > > + .open = socinfo_open, > > + .read = seq_read, > > + .llseek = seq_lseek, > > + .release = seq_release, > > +}; > > + > .. and single_release(), then none of the seq_operations are necessary. > > > +static int __init proc_socinfo_init(void) > > +{ > > + proc_create("socinfo", 0, NULL, &proc_socinfo_operations); > > + return 0; > > +} > > +module_init(proc_socinfo_init); > > proc_create() can fail, so some error handling here would be nice. > > On Mon, May 10, 2010 at 01:37:35PM +0300, Eduardo Valentin wrote: > > +static int c_show(struct seq_file *m, void *v) > > +{ > > + seq_printf(m, "SoC\t: %s\n", socinfo); > > + > > + return 0; > > +} > > + > > +static void *c_start(struct seq_file *m, loff_t *pos) > > +{ > > + return *pos < 1 ? (void *)1 : NULL; > > +} > > + > > +static void *c_next(struct seq_file *m, void *v, loff_t *pos) > > +{ > > + ++*pos; > > + return NULL; > > +} > > + > > +static void c_stop(struct seq_file *m, void *v) > > +{ > > +} > > + > > +const struct seq_operations socinfo_op = { > > + .start = c_start, > > + .next = c_next, > > + .stop = c_stop, > > + .show = c_show > > +}; > > You'll still need the show function, but all of the rest of this is just > duplicating what single_open() already does. If the socinfo string is > static you may also want to rework this a bit so you can just stash the > string in the proc_dir_entry private data. Combine this with something > like kstrdup() and you'll save yourself a bit of stack while you're at > it. While still here, about cleaning this, so, let me see if I got your point. Basically, the file under fs/proc/socinfo.c whould do the thing with single_open & single_release, as you stated. But then there is the .show and its data. One idea would then be to have a function: int register_socinfo_show(int (*show)(struct seq_file *, void *), void *data); Which would be exported to other parts of the kernel (something placed under include/linux/socinfo.h for instance). Then the soc core code (like arch/arm/mach-omap[1,2]) would then register its local show function and pass its data. This way I think we can avoid the exports inside .c files (as in this patch) and also pass the static char * needed during the show. What do you think? BR, -- Eduardo Valentin -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Felipe Balbi on 10 May 2010 14:20 On Mon, May 10, 2010 at 03:08:09PM +0200, Valentin Eduardo (Nokia-D/Helsinki) wrote: >I'm not aware of the module parameter stuff.. but the leak might be other thing >than kstrdup? yeah, I was following the code and the problem is how the kernel handles charp module parameters -- balbi DefectiveByDesign.org -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Paul Mundt on 10 May 2010 23:20 On Mon, May 10, 2010 at 05:22:48PM +0300, Eduardo Valentin wrote: > On Mon, May 10, 2010 at 01:13:00PM +0200, ext Paul Mundt wrote: > > You'll still need the show function, but all of the rest of this is just > > duplicating what single_open() already does. If the socinfo string is > > static you may also want to rework this a bit so you can just stash the > > string in the proc_dir_entry private data. Combine this with something > > like kstrdup() and you'll save yourself a bit of stack while you're at > > it. > > While still here, about cleaning this, so, let me see if I got your point. > Basically, the file under fs/proc/socinfo.c whould do the thing with single_open & > single_release, as you stated. But then there is the .show and its data. > One idea would then be to have a function: > > int register_socinfo_show(int (*show)(struct seq_file *, void *), void *data); > > Which would be exported to other parts of the kernel (something placed under > include/linux/socinfo.h for instance). Then the soc core code > (like arch/arm/mach-omap[1,2]) would then register its local show function and pass its data. > > This way I think we can avoid the exports inside .c files (as in this patch) > and also pass the static char * needed during the show. > > What do you think? > Yes, you'll need something like that. kstrdup() also does an allocation, but you're only going to be registering once and are unlikely to ever unregister (particular since you have this configured as a bool) so that doesn't really matter. On the other hand if the string itself is static you can just pass that in with a static initializer, or have some sort of opaque socinfo data structure that contains the strings you care about. You'll always be able to get back at the pointer through the proc_dir_entry private data. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
First
|
Prev
|
Pages: 1 2 Prev: oprofile hotplug fixes for x86 Next: [PATCH] AT91: PM: dual ram controller support |