Commit 739659cc authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] paride protocols switched to ->owner

Still not safe (we use __MOD_INC_USE_COUNT in paride.c; old code has
MOD_INC_USE_COUNT in protocol drivers), but that takes crap in one
place.

	->owner added
	paride.c grabs/releases it if if present
	->proto_init() became empty for almost everything
	->proto_release() <<--->>
	->proto_init() returns int now (the only case where we do have a
	  non-empty ->proto_init() needed that all along).  paride.c
	  taught to deal with that.
parent f7efec4a
......@@ -131,17 +131,8 @@ static void aten_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void aten_init_proto( PIA *pi )
{ MOD_INC_USE_COUNT;
}
static void aten_release_proto( PIA *pi )
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol aten = {
.owner = THIS_MODULE,
.name = "aten",
.max_mode = 2,
.epp_first = 2,
......@@ -154,8 +145,6 @@ static struct pi_protocol aten = {
.connect = aten_connect,
.disconnect = aten_disconnect,
.log_adapter = aten_log_adapter,
.init_proto = aten_init_proto,
.release_proto = aten_release_proto,
};
static int __init aten_init(void)
......
......@@ -443,17 +443,8 @@ static void bpck_log_adapter( PIA *pi, char * scratch, int verbose )
pi->mode,mode_string[pi->mode],pi->delay);
}
static void bpck_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void bpck_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol bpck = {
.owner = THIS_MODULE,
.name = "bpck",
.max_mode = 5,
.epp_first = 2,
......@@ -469,8 +460,6 @@ static struct pi_protocol bpck = {
.probe_unit = bpck_probe_unit,
.test_proto = bpck_test_proto,
.log_adapter = bpck_log_adapter,
.init_proto = bpck_init_proto,
.release_proto = bpck_release_proto,
};
static int __init bpck_init(void)
......
......@@ -222,38 +222,27 @@ static void bpck6_log_adapter( PIA *pi, char * scratch, int verbose )
pi->unit,pi->mode,mode_string[pi->mode],pi->delay);
}
static void bpck6_init_proto(PIA *pi)
static int bpck6_init_proto(PIA *pi)
{
int i;
PPC *p = kmalloc(sizeof(PPC), GFP_KERNEL);
/* allocate a state structure for this item */
pi->private=(int)kmalloc(sizeof(PPC),GFP_KERNEL);
if(pi->private==(int)NULL)
{
printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n",pi->device);
return;
}
else
{
MOD_INC_USE_COUNT;
if (p) {
memset(p, 0, sizeof(PPC));
pi->private = (int)p;
return 0;
}
for(i=0;i<sizeof(PPC);i++)
{
((unsigned char *)(pi->private))[i]=0;
}
printk(KERN_ERR "%s: ERROR COULDN'T ALLOCATE MEMORY\n", pi->device);
return -1;
}
static void bpck6_release_proto(PIA *pi)
{
MOD_DEC_USE_COUNT;
/* free after use count decremented so that we aren't using it
when it is decremented */
kfree((void *)(pi->private));
}
static struct pi_protocol bpck6 = {
.owner = THIS_MODULE,
.name = "bpck6",
.max_mode = 5,
.epp_first = 2, /* 2-5 use epp (need 8 ports) */
......
......@@ -187,17 +187,8 @@ static void comm_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void comm_init_proto(PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void comm_release_proto(PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol comm = {
.owner = THIS_MODULE,
.name = "comm",
.max_mode = 5,
.epp_first = 2,
......@@ -210,8 +201,6 @@ static struct pi_protocol comm = {
.connect = comm_connect,
.disconnect = comm_disconnect,
.log_adapter = comm_log_adapter,
.init_proto = comm_init_proto,
.release_proto = comm_release_proto,
};
static int __init comm_init(void)
......
......@@ -202,17 +202,8 @@ static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void dstr_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void dstr_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol dstr = {
.owner = THIS_MODULE,
.name = "dstr",
.max_mode = 5,
.epp_first = 2,
......@@ -225,8 +216,6 @@ static struct pi_protocol dstr = {
.connect = dstr_connect,
.disconnect = dstr_disconnect,
.log_adapter = dstr_log_adapter,
.init_proto = dstr_init_proto,
.release_proto = dstr_release_proto,
};
static int __init dstr_init(void)
......
......@@ -301,17 +301,8 @@ static void epat_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void epat_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void epat_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol epat = {
.owner = THIS_MODULE,
.name = "epat",
.max_mode = 6,
.epp_first = 3,
......@@ -325,8 +316,6 @@ static struct pi_protocol epat = {
.disconnect = epat_disconnect,
.test_proto = epat_test_proto,
.log_adapter = epat_log_adapter,
.init_proto = epat_init_proto,
.release_proto = epat_release_proto,
};
static int __init epat_init(void)
......
......@@ -284,17 +284,8 @@ static void epia_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void epia_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void epia_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol epia = {
.owner = THIS_MODULE,
.name = "epia",
.max_mode = 6,
.epp_first = 3,
......@@ -308,8 +299,6 @@ static struct pi_protocol epia = {
.disconnect = epia_disconnect,
.test_proto = epia_test_proto,
.log_adapter = epia_log_adapter,
.init_proto = epia_init_proto,
.release_proto = epia_release_proto,
};
static int __init epia_init(void)
......
......@@ -120,17 +120,8 @@ static void fit2_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void fit2_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void fit2_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol fit2 = {
.owner = THIS_MODULE,
.name = "fit2",
.max_mode = 1,
.epp_first = 2,
......@@ -143,8 +134,6 @@ static struct pi_protocol fit2 = {
.connect = fit2_connect,
.disconnect = fit2_disconnect,
.log_adapter = fit2_log_adapter,
.init_proto = fit2_init_proto,
.release_proto = fit2_release_proto,
};
static int __init fit2_init(void)
......
......@@ -180,17 +180,8 @@ static void fit3_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void fit3_init_proto(PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void fit3_release_proto(PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol fit3 = {
.owner = THIS_MODULE,
.name = "fit3",
.max_mode = 3,
.epp_first = 2,
......@@ -203,8 +194,6 @@ static struct pi_protocol fit3 = {
.connect = fit3_connect,
.disconnect = fit3_disconnect,
.log_adapter = fit3_log_adapter,
.init_proto = fit3_init_proto,
.release_proto = fit3_release_proto,
};
static int __init fit3_init(void)
......
......@@ -233,25 +233,18 @@ static void friq_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void friq_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
pi->private = 0;
}
static void friq_release_proto( PIA *pi)
{ if (pi->private) { /* turn off the power */
{
if (pi->private) { /* turn off the power */
friq_connect(pi);
CMD(0x1d); CMD(0x1e);
friq_disconnect(pi);
pi->private = 0;
}
MOD_DEC_USE_COUNT;
}
static struct pi_protocol friq = {
.owner = THIS_MODULE,
.name = "friq",
.max_mode = 5,
.epp_first = 2,
......@@ -265,7 +258,6 @@ static struct pi_protocol friq = {
.disconnect = friq_disconnect,
.test_proto = friq_test_proto,
.log_adapter = friq_log_adapter,
.init_proto = friq_init_proto,
.release_proto = friq_release_proto,
};
......
......@@ -281,18 +281,8 @@ static void frpw_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void frpw_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
pi->private = 0;
}
static void frpw_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol frpw = {
.owner = THIS_MODULE,
.name = "frpw",
.max_mode = 6,
.epp_first = 2,
......@@ -306,8 +296,6 @@ static struct pi_protocol frpw = {
.disconnect = frpw_disconnect,
.test_proto = frpw_test_proto,
.log_adapter = frpw_log_adapter,
.init_proto = frpw_init_proto,
.release_proto = frpw_release_proto,
};
static int __init frpw_init(void)
......
......@@ -249,17 +249,8 @@ static void k971_log_adapter( PIA *pi, char * scratch, int verbose )
{ kbic_log_adapter(pi,scratch,verbose,"KBIC-971A");
}
static void kbic_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void kbic_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol k951 = {
.owner = THIS_MODULE,
.name = "k951",
.max_mode = 6,
.epp_first = 3,
......@@ -272,11 +263,10 @@ static struct pi_protocol k951 = {
.connect = k951_connect,
.disconnect = k951_disconnect,
.log_adapter = k951_log_adapter,
.init_proto = kbic_init_proto,
.release_proto = kbic_release_proto
};
static struct pi_protocol k971 = {
.owner = THIS_MODULE,
.name = "k971",
.max_mode = 6,
.epp_first = 3,
......@@ -289,8 +279,6 @@ static struct pi_protocol k971 = {
.connect = k971_connect,
.disconnect = k971_disconnect,
.log_adapter = k971_log_adapter,
.init_proto = kbic_init_proto,
.release_proto = kbic_release_proto
};
static int __init kbic_init(void)
......
......@@ -97,17 +97,8 @@ static void ktti_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void ktti_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void ktti_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol ktti = {
.owner = THIS_MODULE,
.name = "ktti",
.max_mode = 1,
.epp_first = 2,
......@@ -120,8 +111,6 @@ static struct pi_protocol ktti = {
.connect = ktti_connect,
.disconnect = ktti_disconnect,
.log_adapter = ktti_log_adapter,
.init_proto = ktti_init_proto,
.release_proto = ktti_release_proto,
};
static int __init ktti_init(void)
......
......@@ -122,17 +122,8 @@ static void on20_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void on20_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void on20_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol on20 = {
.owner = THIS_MODULE,
.name = "on20",
.max_mode = 2,
.epp_first = 2,
......@@ -145,8 +136,6 @@ static struct pi_protocol on20 = {
.connect = on20_connect,
.disconnect = on20_disconnect,
.log_adapter = on20_log_adapter,
.init_proto = on20_init_proto,
.release_proto = on20_release_proto,
};
static int __init on20_init(void)
......
......@@ -287,17 +287,8 @@ static void on26_log_adapter( PIA *pi, char * scratch, int verbose )
}
static void on26_init_proto( PIA *pi)
{ MOD_INC_USE_COUNT;
}
static void on26_release_proto( PIA *pi)
{ MOD_DEC_USE_COUNT;
}
static struct pi_protocol on26 = {
.owner = THIS_MODULE,
.name = "on26",
.max_mode = 5,
.epp_first = 2,
......@@ -311,8 +302,6 @@ static struct pi_protocol on26 = {
.disconnect = on26_disconnect,
.test_port = on26_test_port,
.log_adapter = on26_log_adapter,
.init_proto = on26_init_proto,
.release_proto = on26_release_proto,
};
static int __init on26_init(void)
......
......@@ -106,7 +106,6 @@ void pi_do_claimed(PIA * pi, void (*cont) (void))
unsigned long flags;
spin_lock_irqsave(&pi_spinlock, flags);
if (pi->pardev && parport_claim(pi->pardev)) {
pi->claim_cont = cont;
spin_unlock_irqrestore(&pi_spinlock, flags);
......@@ -118,7 +117,6 @@ void pi_do_claimed(PIA * pi, void (*cont) (void))
cont();
}
EXPORT_SYMBOL(pi_do_claimed);
static void pi_claim(PIA * pi)
......@@ -175,39 +173,31 @@ void pi_release(PIA * pi)
if (pi->reserved)
release_region(pi->port, pi->reserved);
#endif /* !CONFIG_PARPORT */
pi->proto->release_proto(pi);
if (pi->proto->release_proto)
pi->proto->release_proto(pi);
if (pi->proto->owner)
__MOD_DEC_USE_COUNT(pi->proto->owner);
}
EXPORT_SYMBOL(pi_release);
#define WR(r,v) pi_write_regr(pi,0,r,v)
#define RR(r) (pi_read_regr(pi,0,r))
static int pi_test_proto(PIA * pi, char *scratch, int verbose)
static int default_test_proto(PIA * pi, char *scratch, int verbose)
{
int j, k;
int e[2] = { 0, 0 };
if (pi->proto->test_proto) {
pi_claim(pi);
j = pi->proto->test_proto(pi, scratch, verbose);
pi_unclaim(pi);
return j;
}
pi_connect(pi);
pi->proto->connect(pi);
for (j = 0; j < 2; j++) {
WR(6, 0xa0 + j * 0x10);
pi_write_regr(pi, 0, 6, 0xa0 + j * 0x10);
for (k = 0; k < 256; k++) {
WR(2, k ^ 0xaa);
WR(3, k ^ 0x55);
if (RR(2) != (k ^ 0xaa))
pi_write_regr(pi, 0, 2, k ^ 0xaa);
pi_write_regr(pi, 0, 3, k ^ 0x55);
if (pi_read_regr(pi, 0, 2) != (k ^ 0xaa))
e[j]++;
}
}
pi_disconnect(pi);
pi->proto->disconnect(pi);
if (verbose)
printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
......@@ -217,6 +207,20 @@ static int pi_test_proto(PIA * pi, char *scratch, int verbose)
return (e[0] && e[1]); /* not here if both > 0 */
}
static int pi_test_proto(PIA * pi, char *scratch, int verbose)
{
int res;
pi_claim(pi);
if (pi->proto->test_proto)
res = pi->proto->test_proto(pi, scratch, verbose);
else
res = default_test_proto(pi, scratch, verbose);
pi_unclaim(pi);
return res;
}
int pi_register(PIP * pr)
{
int k;
......@@ -384,40 +388,52 @@ int pi_init(PIA * pi, int autoprobe, int port, int mode,
}
for (p = s; p < e; p++) {
if (protocols[p]) {
pi->proto = protocols[p];
pi->private = 0;
pi->proto->init_proto(pi);
if (delay == -1)
pi->delay = pi->proto->default_delay;
else
pi->delay = delay;
pi->devtype = devtype;
pi->device = device;
pi->parname = NULL;
pi->pardev = NULL;
init_waitqueue_head(&pi->parq);
pi->claimed = 0;
pi->claim_cont = NULL;
pi->mode = mode;
if (port != -1) {
pi->port = port;
if (pi_probe_unit(pi, unit, scratch, verbose))
break;
pi->port = 0;
} else {
k = 0;
while ((pi->port = lpts[k++]))
if (pi_probe_unit
(pi, unit, scratch, verbose))
break;
if (pi->port)
struct pi_protocol *proto = protocols[p];
if (!proto)
continue;
/* still racy */
if (proto->owner)
__MOD_INC_USE_COUNT(proto->owner);
pi->proto = proto;
pi->private = 0;
if (proto->init_proto && proto->init_proto(pi) < 0) {
pi->proto = NULL;
if (proto->owner)
__MOD_DEC_USE_COUNT(proto->owner);
continue;
}
if (delay == -1)
pi->delay = pi->proto->default_delay;
else
pi->delay = delay;
pi->devtype = devtype;
pi->device = device;
pi->parname = NULL;
pi->pardev = NULL;
init_waitqueue_head(&pi->parq);
pi->claimed = 0;
pi->claim_cont = NULL;
pi->mode = mode;
if (port != -1) {
pi->port = port;
if (pi_probe_unit(pi, unit, scratch, verbose))
break;
pi->port = 0;
} else {
k = 0;
while ((pi->port = lpts[k++]))
if (pi_probe_unit
(pi, unit, scratch, verbose))
break;
}
pi->proto->release_proto(pi);
if (pi->port)
break;
}
if (pi->proto->release_proto)
pi->proto->release_proto(pi);
if (proto->owner)
__MOD_DEC_USE_COUNT(proto->owner);
}
if (!pi->port) {
......
......@@ -155,8 +155,9 @@ struct pi_protocol {
int (*test_proto)(PIA *,char *,int);
void (*log_adapter)(PIA *,char *,int);
void (*init_proto)(PIA *);
int (*init_proto)(PIA *);
void (*release_proto)(PIA *);
struct module *owner;
};
typedef struct pi_protocol PIP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment