parport: add device model
Sudip Mukherjee
maintainerPATCH 1/1 parport: add device model
This is work-in-progree, not for applying to any tree. Posting now for your comments so that I know if I am in the proper track.
in parport_register_driver() driver is registered but i am not linking anywhere the device with the driver, but yet when I am testing this patch I am seeing in sys tree that parport0 is linked with the lp driver. Is it done in the device core? I am missing this step somewhere.
In parport_claim() the attach is unchecked as of now, I think we will need my initial patch series of monitoring the attach return value along with it.
while testing I am getting NULL dereference with daisy.c, and after disabling PARPORT_1284 , I am getting some new errors. so if you are testing this patch please keep in mind that still lots of work is pending.
My main intention to post it now is to know if my approach is correct.
--- drivers/parport/procfs.c | 12 ++++++-- drivers/parport/share.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/parport.h | 21 +++++++++++++- 3 files changed, 99 insertions(+), 6 deletions(-)
drivers/parport/procfs.c +10 -2
@@ -558,9 +558,15 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { +int ret; + parport_default_sysctl_table.sysctl_header =register_sysctl_table (parport_default_sysctl_table.dev_dir); -return 0 ; + ret =parport_bus_init (); +if (ret) +unregister_sysctl_table (parport_default_sysctl_table. + sysctl_header); +return ret; } static void __exit parport_default_proc_unregister(void)
@@ -570,6 +576,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header = NULL; } +parport_bus_exit (); }#else /* no sysctl or no procfs*/
@@ -596,11 +603,12 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { -return 0 ; +return parport_bus_init (); } static void __exit parport_default_proc_unregister (void) { +parport_bus_exit (); }#endif
drivers/parport/share.c +69 -3
158 lines not on this page · raw message
include/linux/parport.h +20 -1
@@ -15,6 +15,7 @@#include <linux/semaphore.h> #include <asm/ptrace.h> #include <uapi/linux/parport.h> +#include <linux/device.h> /* Define this later. */ struct parport ;
@@ -146,6 +147,7 @@ struct pardevice {struct pardevice *next;struct pardevice *prev;struct parport_state *state;/* saved status over preemption */ +struct device dev;wait_queue_head_t wait_q;unsigned long int time;unsigned long int timeslice;
@@ -156,6 +158,11 @@ struct pardevice {void * sysctl_table; }; +static inline struct pardevice *to_pardevice (struct device *n) +{ + return container_of(n, struct pardevice, dev); +} +/* IEEE1284 information */ /* IEEE1284 phases. These are exposed to userland through ppdev IOCTL
@@ -195,6 +202,7 @@ struct parport {* This may unfortulately be null if the * port has a legacy driver. */ +struct device ddev;/* to link with the bus */ struct parport *physport;/* If this is a non-default mux
@@ -251,6 +259,7 @@ struct parport_driver {const char *name;void (*attach) (struct parport *);void (*detach) (struct parport *); +struct device_driver driver;struct list_head list; };
@@ -267,12 +276,22 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,determining the IEEE 1284.3 topology of the port and collecting DeviceIDs). */ void parport_announce_port (struct parport *port); +void parport_bus_exit (void ); +extern struct bus_type parport_bus_type; +int parport_bus_init (void );/* Unregister a port. */ extern void parport_remove_port (struct parport *port);/* Register a new high-level driver. */ -extern int parport_register_driver (struct parport_driver *); +int __parport_register_driver (struct parport_driver *, +struct module *,const char *); +/* +* parport_register_driver must be a macro so that KBUILD_MODNAME can +* be expanded +*/ +#define parport_register_driver (driver) \ + __parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)/* Unregister a high-level driver. */ extern void parport_unregister_driver (struct parport_driver *);
Signature · 1 line
1.8.1.2
Quoted 31 lines · Sudip Mukherjee
This is work-in-progree, not for applying to any tree. Posting now for your comments so that I know if I am in the proper track.
in
parport_register_driver()driver is registered but i am not linking anywhere the device with the driver, but yet when I am testing this patch I am seeing in sys tree that parport0 is linked with the lp driver. Is it done in the device core? I am missing this step somewhere.In
parport_claim()the attach is unchecked as of now, I think we will need my initial patch series of monitoring the attach return value along with it.while testing I am getting NULL dereference with
daisy.c, and after disablingPARPORT_1284, I am getting some new errors. so if you are testing this patch please keep in mind that still lots of work is pending.
My main intention to post it now is to know if my approach is correct.Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/parport/procfs.c | 12 ++++++-- drivers/parport/share.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/parport.h | 21 +++++++++++++- 3 files changed, 99 insertions(+), 6 deletions(-)drivers/parport/procfs.c +0
-0
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 564
Quoted 7 lines
drivers/parport/procfs.c +2
-0@@ -558,9 +558,15 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { +int ret; + parport_default_sysctl_table.sysctl_header =register_sysctl_table (parport_default_sysctl_table.dev_dir);
Should we return an error if this fails?
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 568
Quoted 5 lines
drivers/parport/procfs.c +4
-1-return 0 ; + ret =parport_bus_init (); +if (ret) +unregister_sysctl_table (parport_default_sysctl_table. + sysctl_header);
ret = parport_bus_init();
if (ret) {
unregister_sysctl_table(
parport_default_sysctl_table.sysctl_header);
return ret;
}
return 0;drivers/parport/procfs.c static void __exit parport_default_proc_unregister(void) · line 579
Quoted 9 lines
drivers/parport/procfs.c +2
-0+return ret; } static void __exit parport_default_proc_unregister(void)@@ -570,6 +576,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header =NULL ; } +parport_bus_exit ();
Do we need this function? Can't we call bus_unregister() directly?
Quoted 37 lines
drivers/parport/procfs.c +2
-1}#else /* no sysctl or no procfs*/ @@ -596,11 +603,12 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { -return 0 ; +return parport_bus_init (); } static void __exit parport_default_proc_unregister (void) { +parport_bus_exit (); }#endif drivers/parport/share.c +5
-0@@ -29,6 +29,7 @@#include <linux/slab.h> #include <linux/sched.h> #include <linux/kmod.h> +#include <linux/device.h> #include <linux/spinlock.h> #include <linux/mutex.h> @@ -100,6 +101,33 @@ static struct parport_operations dead_ops = { .owner = NULL, }; +/* +* This currently matches any parport driver to any parport device +* drivers themselves make the decision whether to drive this device +* in their probe method.
drivers/parport/share.c static struct parport_operations dead_ops = { · line 117
Quoted 10 lines
drivers/parport/share.c +10
-0+*/ + +static int parport_match (struct device *dev,struct device_driver *drv) +{ +return 1 ; +} + +struct bus_type parport_bus_type = { + .name ="parport" , + .match = parport_match,
There is no need for a match function. If it's NULL that's the same a "return 1" fuction. This is called from driver_match_device().
Quoted 32 lines
drivers/parport/share.c +16
-1+}; +EXPORT_SYMBOL (parport_bus_type); + +int parport_bus_init (void ) +{ +return bus_register (&parport_bus_type); +} + +void parport_bus_exit (void ) +{ +bus_unregister (&parport_bus_type); +} +/* Call attach(port) for each registered driver. */ static void attach_driver_chain (struct parport *port) {@@ -151,9 +179,11 @@ static void get_lowlevel_driver (void)* Returns 0 on success. Currently it always succeeds. **/ -int parport_register_driver (struct parport_driver *drv) +int __parport_register_driver (struct parport_driver *drv, +struct module *owner,const char *mod_name) {struct parport *port; +int ret;if (list_empty (&portlist))get_lowlevel_driver ();@@ -164,7 +194,22 @@ int parport_register_driver (struct parport_driver *drv)list_add (&drv->list, &drivers);mutex_unlock (®istration_lock);
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 204
Quoted 10 lines
drivers/parport/share.c +8
-1-return 0 ; + drv->driver.name = drv->name; + drv->driver.bus = &parport_bus_type; + drv->driver.owner = owner; + drv->driver.mod_name = mod_name; + +/* register with core */ + ret =driver_register (&drv->driver); +if (ret <0 ) {
if (ret) {drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 208
Quoted 4 lines
drivers/parport/share.c +4
-0+mutex_lock (®istration_lock); +list_del_init (&drv->list); +list_for_each_entry (port, &portlist, list) + drv->detach (port);
Does this free port? Should this be list_for_each_entry_safe?
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 209
Quoted 1 line
drivers/parport/share.c +1
-0+mutex_unlock (®istration_lock);
return ret;
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 212
Quoted 3 lines
drivers/parport/share.c +3
-0+ } + +return ret;
return 0;
Quoted 29 lines
drivers/parport/share.c +4
-0}/** @@ -188,6 +233,7 @@ void parport_unregister_driver (struct parport_driver *drv) {struct parport *port; +driver_unregister (&drv->driver);mutex_lock (®istration_lock);list_del_init (&drv->list);list_for_each_entry (port, &portlist, list)@@ -281,6 +327,7 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,int num;int device;char *name; +int ret; tmp =kzalloc (sizeof (struct parport ),GFP_KERNEL );if (!tmp) {@@ -333,6 +380,8 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,*/ sprintf (name,"parport%d" , tmp->portnum = tmp->number); tmp->name = name; + tmp->ddev.bus = &parport_bus_type; + tmp->ddev.init_name = name;for (device =0 ; device <5 ; device++)/* assume the worst */
drivers/parport/share.c struct parport *parport_register_port(unsigned long base, int irq, int dma, · line 393
Quoted 5 lines
drivers/parport/share.c +2
-0@@ -340,6 +389,12 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, tmp->waithead = tmp->waittail =NULL ; + ret =device_register (&tmp->ddev); +if (ret <0 ) {
if (ret) {Quoted 22 lines
drivers/parport/share.c +7
-0+kfree (tmp); +return NULL ; + } +return tmp; }@@ -442,6 +497,8 @@ void parport_remove_port(struct parport *port)mutex_unlock (®istration_lock); +device_unregister (&port->ddev); +parport_proc_unregister (port);for (i =1 ; i <3 ; i++) {@@ -774,12 +831,19 @@ int parport_claim(struct pardevice *dev)struct pardevice *oldcad;struct parport *port = dev->port->physport;unsigned long flags; +int ret;
drivers/parport/share.c int parport_claim(struct pardevice *dev) · line 845
Quoted 10 lines
drivers/parport/share.c +5
-0if (port->cad == dev) {printk (KERN_INFO "%s: %s already owner\n" , dev->port->name,dev->name);return 0 ; } + dev->dev.bus = &parport_bus_type; + dev->dev.parent = &port->ddev; + dev->dev.init_name = dev->name; + ret =device_register (&dev->dev); +if (ret <0 )
Please use "if (ret) " everywhere unless it returns positive on success.
I know that I have done a rubbish review. I'm going to have to review this properly later.
regards,
dan carpenter
Sudip Mukherjee
maintainerQuoted 1 line · Dan Carpenter
On Fri, Apr 10, 2015 at 08:00:38PM +0530, Sudip Mukherjee wrote:
<snip>
Quoted 5 lines
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 564
Quoted 3 lines
drivers/parport/procfs.c +1
-0+ parport_default_sysctl_table.sysctl_header =register_sysctl_table (parport_default_sysctl_table.dev_dir);Should we return an error if this fails?
not sure. but even if it fails it will not affect the normal functioning of the parallel port. but I will add that in the next WIP patch.
Quoted 16 lines
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 568
Quoted 6 lines
drivers/parport/procfs.c +4
-1-return 0 ; + ret =parport_bus_init (); +if (ret) +unregister_sysctl_table (parport_default_sysctl_table. + sysctl_header);ret = parport_bus_init(); if (ret) { unregister_sysctl_table( parport_default_sysctl_table.sysctl_header); return ret; } return 0;
do we need two returns here? parport_bus_init() will return 0 if it succeeds, so return ret will return either 0 or the error code whatever the case maybe.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +1
-0+ return ret; }
Quoted 8 lines
drivers/parport/procfs.c static void __exit parport_default_proc_unregister(void) · line 579
Quoted 6 lines
static void
__exitparport_default_proc_unregister(void)drivers/parport/procfs.c +1
-0@@ -570,6 +576,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header =NULL ; } +parport_bus_exit ();Do we need this function? Can't we call
bus_unregister()directly?
no, we dont need. on similar reasoning we also donot need parport_bus_init(). I will remove both. :)
Quoted 1 line
<snip>
Quoted 7 lines
drivers/parport/share.c static struct parport_operations dead_ops = { · line 117
Quoted 4 lines
drivers/parport/share.c +3
-0+struct bus_type parport_bus_type = { + .name ="parport" , + .match = parport_match,There is no need for a match function. If it's NULL that's the same a "return 1" fuction. This is called from
driver_match_device().
ok.
Quoted 1 line
<snip>
Quoted 11 lines
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 204
Quoted 2 lines
drivers/parport/share.c +2
-0+ ret =driver_register (&drv->driver); +if (ret <0 ) {if (ret) {drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 208
Quoted 4 lines
drivers/parport/share.c +4
-0+mutex_lock (®istration_lock); +list_del_init (&drv->list); +list_for_each_entry (port, &portlist, list) + drv->detach (port);Does this free port? Should this be
list_for_each_entry_safe?
I am not sure what you meant by "free port". attach will claim the port, and the port will be marked. detach will just remove that connection and the driver will release the port.
Quoted 9 lines
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 209
Quoted 2 lines
drivers/parport/share.c +1
-0+mutex_unlock (®istration_lock);return ret;drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 212
Quoted 3 lines
drivers/parport/share.c +3
-0+ } + +return ret;return 0;
do we need two returns? as ret will be either 0 or error code.
Quoted 3 lines
Quoted 3 lines
}
<snip>
Quoted 2 lines
Please use "if (ret) " everywhere unless it returns positive on success.
sure.
Quoted 3 lines
I know that I have done a rubbish review. I'm going to have to review this properly later.
main thing i wanted to know is if my approach is correct. since nothing on that so I hope I am on the correct track. Thanks.
I will send in the next version in a day or two.
regards
sudip
Quoted 3 lines
regards,
dan carpenter
Quoted 5 lines · Sudip Mukherjee
Quoted 2 lines
I know that I have done a rubbish review. I'm going to have to review this properly later.
main thing i wanted to know is if my approach is correct. since nothing on that so I hope I am on the correct track. Thanks.
I will send in the next version in a day or two.
At quick glance, you are on the right track. Writing a new bus is hard, I know, the documentation is lacking and it's tricky in places and the api is horrid in others. I know this, just never had the time to make it easier, so if you have any questions about it, please let me know.
thanks,
greg k-h
Sudip Mukherjee
maintainerQuoted 11 lines · Greg KH
Quoted 5 lines · Sudip Mukherjee
Quoted 2 lines
I know that I have done a rubbish review. I'm going to have to review this properly later.
main thing i wanted to know is if my approach is correct. since nothing on that so I hope I am on the correct track. Thanks.
I will send in the next version in a day or two.At quick glance, you are on the right track. Writing a new bus is hard, I know, the documentation is lacking and it's tricky in places and the api is horrid in others. I know this, just never had the time to make it easier, so if you have any questions about it, please let me know.
well, as of now one question. I am planning like this :
sys
_______________|_____________
| | | | |
bus
________|______
|
parport
_______|_____
| |
devices drivers- lp, ppdev, panel etc..
_____|________
| |
parport0 parport1I can understand that drivers need to be binded to one device, so suppose ppdev wants to use parport0, how that binding will be done? do i need mark the driver in the parport->ddev.driver ? I think that should have been automatically done if i have a probe function for the bus...
somehow I am missing this step in the other drivers codes.
regards
sudip
Quoted 4 lines
thanks,
greg k-h
Sudip Mukherjee
maintainerQuoted 19 lines · Sudip Mukherjee
Quoted 1 line · Greg KH
On Sat, Apr 11, 2015 at 10:56:51AM +0530, Sudip Mukherjee wrote:
well, as of now one question. I am planning like this :
sys _______________|_____________ | | | | | bus ________|______ | parport _______|_____ | | devices drivers- lp, ppdev, panel etc.. _____|________ | | parport0 parport1
Quoted 6 lines
I can understand that drivers need to be binded to one device, so suppose ppdev wants to use parport0, how that binding will be done? do i need mark the driver in the
parport->ddev.driver? I think that should have been automatically done if i have a probe function for the bus...
somehow I am missing this step in the other drivers codes.
i think i got the missing link, let me try first.
regards
sudip
Quoted 29 lines · Sudip Mukherjee
Quoted 11 lines · Greg KH
Quoted 5 lines · Sudip Mukherjee
Quoted 2 lines
I know that I have done a rubbish review. I'm going to have to review this properly later.
main thing i wanted to know is if my approach is correct. since nothing on that so I hope I am on the correct track. Thanks.
I will send in the next version in a day or two.At quick glance, you are on the right track. Writing a new bus is hard, I know, the documentation is lacking and it's tricky in places and the api is horrid in others. I know this, just never had the time to make it easier, so if you have any questions about it, please let me know.
well, as of now one question. I am planning like this :
sys _______________|_____________ | | | | | bus ________|______ | parport _______|_____ | | devices drivers- lp, ppdev, panel etc.. _____|________ | | parport0 parport1
Quoted 2 lines
I can understand that drivers need to be binded to one device, so suppose ppdev wants to use parport0, how that binding will be done?
The driver core does the "binding".
Quoted 1 line
do i need mark the driver in the
parport->ddev.driver?
No, just have the probe function for the ppdev function return 0, meaning it successfully bound to the driver that was passed to it and all will be fine.
Quoted 2 lines
I think that should have been automatically done if i have a probe function for the bus...
Yes.
Quoted 1 line
somehow I am missing this step in the other drivers codes.
Hope this helps,
greg k-h
Sudip Mukherjee
maintainerQuoted 3 lines · Greg KH
Quoted 2 lines · Sudip Mukherjee
Quoted 1 line · Greg KH
On Sat, Apr 11, 2015 at 10:56:51AM +0530, Sudip Mukherjee wrote:
<snip>
Quoted 5 lines
Quoted 4 lines
I can understand that drivers need to be binded to one device, so suppose ppdev wants to use parport0, how that binding will be done?
Quoted 7 lines
The driver core does the "binding".
Quoted 1 line
do i need mark the driver in the
parport->ddev.driver?No, just have the probe function for the ppdev function return 0, meaning it successfully bound to the driver that was passed to it and all will be fine.
well, I was thinking that instead of having probe for individual drivers (then we need to modify all the drivers), i was planning like:
when the driver calls parport_device_register(), the driver will be registered under parport and also a subdevice will be created under the particular parport the driver wants to use and both will have the same name. The probe of the bus will verify that name comparison and will return 0 if the name matches. is this plan ok ?
and i wanted the binding to happen when the driver calls parport_claim() and for that I was thinking of calling device_attach() . is that also ok?
regards
sudip
Quoted 11 lines
Quoted 3 lines
I think that should have been automatically done if i have a probe function for the bus...
Yes.
Quoted 1 line
somehow I am missing this step in the other drivers codes.
Hope this helps,
greg k-h
Quoted 12 lines · Sudip Mukherjee
Quoted 3 lines · Greg KH
Quoted 2 lines · Sudip Mukherjee
Quoted 1 line · Greg KH
On Sat, Apr 11, 2015 at 10:56:51AM +0530, Sudip Mukherjee wrote:
<snip>
Quoted 7 lines
Quoted 4 lines
I can understand that drivers need to be binded to one device, so suppose ppdev wants to use parport0, how that binding will be done?
The driver core does the "binding".
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
do i need mark the driver in the
parport->ddev.driver?No, just have the probe function for the ppdev function return 0, meaning it successfully bound to the driver that was passed to it and all will be fine.
well, I was thinking that instead of having probe for individual drivers (then we need to modify all the drivers),
Sorry, you will have to modify all drivers, that's going to be a requirement.
Quoted 8 lines
i was planning like:
when the driver callsparport_device_register(), the driver will be registered under parport and also a subdevice will be created under the particular parport the driver wants to use and both will have the same name. The probe of the bus will verify that name comparison and will return 0 if the name matches. is this plan ok ?
and i wanted the binding to happen when the driver callsparport_claim()and for that I was thinking of callingdevice_attach(). is that also ok?
I don't know what parport_claim() does, sorry, but you are going to have to change all drivers.
I suggest working on adding the new parport bus, and convert one or two drivers to the new code, to get it working first. Then you can convert the other drivers and then delete the old registration code from the parport core, as it will be not used anymore.
good luck,
greg k-h
Quoted 10 lines · Sudip Mukherjee
Quoted 1 line · Dan Carpenter
On Fri, Apr 10, 2015 at 08:00:38PM +0530, Sudip Mukherjee wrote:
<snip>
Quoted 5 lines
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 564
Quoted 3 lines
drivers/parport/procfs.c +1
-0+ parport_default_sysctl_table.sysctl_header =register_sysctl_table (parport_default_sysctl_table.dev_dir);Should we return an error if this fails?
not sure. but even if it fails it will not affect the normal functioning of the parallel port. but I will add that in the next WIP patch.
Probably, it's better to leave it as-is if you aren't sure. I was just asking because I didn't know myself.
Quoted 15 lines
Quoted 15 lines
drivers/parport/procfs.c int parport_device_proc_unregister(struct pardevice *device) · line 568
Quoted 6 lines
drivers/parport/procfs.c +4
-1-return 0 ; + ret =parport_bus_init (); +if (ret) +unregister_sysctl_table (parport_default_sysctl_table. + sysctl_header);ret = parport_bus_init(); if (ret) { unregister_sysctl_table( parport_default_sysctl_table.sysctl_header); return ret; }
Quoted 3 lines
Quoted 1 line
return 0;do we need two returns here?
parport_bus_init()will return 0 if it succeeds, so return ret will return either 0 or the error code whatever the case maybe.
Yes, they work the same, you're right. But the other style is better and more robust.
I have been trying to explain this to people but "return 0;" is beautiful code. Functions normally are a list of statements in a row with exceptions for error handling. The last statement in the success path should be "return 0;".
Don't mix error and success paths. I see a quite a few bugs like this where the error handling doesn't have a return then later we add some code at the end of the function and forget to add the return.
ret = parport_bus_init(); if (ret) unregister_sysctl_table(); ret = something_else(); return ret;
Quoted 38 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +1
-0+ return ret; }Quoted 8 lines
drivers/parport/procfs.c static void __exit parport_default_proc_unregister(void) · line 579
Quoted 6 lines
static void
__exitparport_default_proc_unregister(void)drivers/parport/procfs.c +1
-0@@ -570,6 +576,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header =NULL ; } +parport_bus_exit ();Do we need this function? Can't we call
bus_unregister()directly?no, we dont need. on similar reasoning we also donot need
parport_bus_init(). I will remove both. :)Quoted 1 line
<snip>
Quoted 7 lines
drivers/parport/share.c static struct parport_operations dead_ops = { · line 117
Quoted 4 lines
drivers/parport/share.c +3
-0+struct bus_type parport_bus_type = { + .name ="parport" , + .match = parport_match,There is no need for a match function. If it's NULL that's the same a "return 1" fuction. This is called from
driver_match_device().ok.
Quoted 1 line
<snip>
Quoted 11 lines
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 204
Quoted 2 lines
drivers/parport/share.c +2
-0+ ret =driver_register (&drv->driver); +if (ret <0 ) {if (ret) {drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 208
Quoted 4 lines
drivers/parport/share.c +4
-0+mutex_lock (®istration_lock); +list_del_init (&drv->list); +list_for_each_entry (port, &portlist, list) + drv->detach (port);Does this free port? Should this be
list_for_each_entry_safe?
Quoted 3 lines
I am not sure what you meant by "free port". attach will claim the port, and the port will be marked. detach will just remove that connection and the driver will release the port.
My concern is that we dereference port to get the next port. If it's freed now it causes a use after free. It's easier to detect if you have free poisoning turned on.
Quoted 15 lines
Quoted 9 lines
drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 209
Quoted 2 lines
drivers/parport/share.c +1
-0+mutex_unlock (®istration_lock);return ret;drivers/parport/share.c int parport_register_driver (struct parport_driver *drv) · line 212
Quoted 3 lines
drivers/parport/share.c +3
-0+ } + +return ret;return 0;do we need two returns? as ret will be either 0 or error code.
Quoted 3 lines
Quoted 3 lines
}
<snip>
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Please use "if (ret) " everywhere unless it returns positive on success.
sure.
Quoted 3 lines
I know that I have done a rubbish review. I'm going to have to review this properly later.
main thing i wanted to know is if my approach is correct. since nothing on that so I hope I am on the correct track. Thanks.
I will send in the next version in a day or two.
Heh. No, I really know less than you do about the driver model at this point. Sorry. It's going to take me a bit to get up to speed.
regards,
dan carpenter
Quoted 13 lines · On Friday 10 April 2015 16:30:38 Sudip Mukherjee wrote:
This is work-in-progree, not for applying to any tree. Posting now for your comments so that I know if I am in the proper track.
in
parport_register_driver()driver is registered but i am not linking anywhere the device with the driver, but yet when I am testing this patch I am seeing in sys tree that parport0 is linked with the lp driver. Is it done in the device core? I am missing this step somewhere.In
parport_claim()the attach is unchecked as of now, I think we will need my initial patch series of monitoring the attach return value along with it.
Quoted 5 lines
while testing I am getting NULL dereference with
daisy.c, and after disablingPARPORT_1284, I am getting some new errors. so if you are testing this patch please keep in mind that still lots of work is pending.
My main intention to post it now is to know if my approach is correct.
Many newer parallel port devices support plug&play (IEEE1284 device ID) but Linux never supported it properly. The ID is probed and even the class is printed in the kernel log (drivers/parport/probe.c) but there's no support for module autoloading based on that.
This could be a good opportunity to add this support. I was thinking about this while playing with some parport webcams recently.
Signature · 1 line
Ondrej Zary
Sudip Mukherjee
maintainerQuoted 8 lines · Ondrej Zary
On Friday 10 April 2015 16:30:38 Sudip Mukherjee wrote:
Many newer parallel port devices support plug&play (IEEE1284 device ID) but Linux never supported it properly. The ID is probed and even the class is printed in the kernel log (
drivers/parport/probe.c) but there's no support for module autoloading based on that.
This could be a good opportunity to add this support. I was thinking about this while playing with some parport webcams recently.
I think yes, or maybe immediately after this updation is over. But the main problem for me will be to get hold of a plug&play parallel port device. is any available now? Can you please suggest one other than webcam so that you can test on webcam and I can test it on something else.
regards
sudip
Quoted 3 lines
Signature · 2 lines
-- Ondrej Zary
Quoted 10 lines · On Saturday 11 April 2015 07:05:11 you wrote:
Quoted 8 lines · Ondrej Zary
On Friday 10 April 2015 16:30:38 Sudip Mukherjee wrote:
Many newer parallel port devices support plug&play (IEEE1284 device ID) but Linux never supported it properly. The ID is probed and even the class is printed in the kernel log (
drivers/parport/probe.c) but there's no support for module autoloading based on that.
This could be a good opportunity to add this support. I was thinking about this while playing with some parport webcams recently.
Quoted 5 lines
I think yes, or maybe immediately after this updation is over. But the main problem for me will be to get hold of a plug&play parallel port device. is any available now? Can you please suggest one other than webcam so that you can test on webcam and I can test it on something else.
Most printers produced since 1995 or 1996 are plug&play capable (lp module could be loaded if a printer-class device is found) and also external drives (ZIP, LS-120).
Signature · 1 line
Ondrej Zary