Skip to content

Commit abc4559

Browse files
bwhacksdavem330
authored andcommitted
via-ircc: Use pci_{get, set}_drvdata() instead of static pointer variable
via-ircc still maintains its own array of device pointers in Linux 2.4 style. Worse, it always uses index 0, so it will crash if there are multiple suitable devices in the system. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 93ca3bb commit abc4559

1 file changed

Lines changed: 15 additions & 67 deletions

File tree

‎drivers/net/irda/via-ircc.c‎

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,9 @@ static int dongle_id = 0; /* default: probe */
7575
/* We can't guess the type of connected dongle, user *must* supply it. */
7676
module_param(dongle_id, int, 0);
7777

78-
/* FIXME : we should not need this, because instances should be automatically
79-
* managed by the PCI layer. Especially that we seem to only be using the
80-
* first entry. Jean II */
81-
/* Max 4 instances for now */
82-
static struct via_ircc_cb *dev_self[] = { NULL, NULL, NULL, NULL };
83-
8478
/* Some prototypes */
85-
static int via_ircc_open(int i, chipio_t * info, unsigned int id);
86-
static int via_ircc_close(struct via_ircc_cb *self);
79+
static int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
80+
unsigned int id);
8781
static int via_ircc_dma_receive(struct via_ircc_cb *self);
8882
static int via_ircc_dma_receive_complete(struct via_ircc_cb *self,
8983
int iobase);
@@ -215,7 +209,7 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
215209
pci_write_config_byte(pcidev,0x42,(bTmp | 0xf0));
216210
pci_write_config_byte(pcidev,0x5a,0xc0);
217211
WriteLPCReg(0x28, 0x70 );
218-
if (via_ircc_open(0, &info,0x3076) == 0)
212+
if (via_ircc_open(pcidev, &info, 0x3076) == 0)
219213
rc=0;
220214
} else
221215
rc = -ENODEV; //IR not turn on
@@ -254,7 +248,7 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
254248
info.irq=FirIRQ;
255249
info.dma=FirDRQ1;
256250
info.dma2=FirDRQ0;
257-
if (via_ircc_open(0, &info,0x3096) == 0)
251+
if (via_ircc_open(pcidev, &info, 0x3096) == 0)
258252
rc=0;
259253
} else
260254
rc = -ENODEV; //IR not turn on !!!!!
@@ -264,48 +258,10 @@ static int __devinit via_init_one (struct pci_dev *pcidev, const struct pci_devi
264258
return rc;
265259
}
266260

267-
/*
268-
* Function via_ircc_clean ()
269-
*
270-
* Close all configured chips
271-
*
272-
*/
273-
static void via_ircc_clean(void)
274-
{
275-
int i;
276-
277-
IRDA_DEBUG(3, "%s()\n", __func__);
278-
279-
for (i=0; i < ARRAY_SIZE(dev_self); i++) {
280-
if (dev_self[i])
281-
via_ircc_close(dev_self[i]);
282-
}
283-
}
284-
285-
static void __devexit via_remove_one (struct pci_dev *pdev)
286-
{
287-
IRDA_DEBUG(3, "%s()\n", __func__);
288-
289-
/* FIXME : This is ugly. We should use pci_get_drvdata(pdev);
290-
* to get our driver instance and call directly via_ircc_close().
291-
* See vlsi_ir for details...
292-
* Jean II */
293-
via_ircc_clean();
294-
295-
/* FIXME : This should be in via_ircc_close(), because here we may
296-
* theoritically disable still configured devices :-( - Jean II */
297-
pci_disable_device(pdev);
298-
}
299-
300261
static void __exit via_ircc_cleanup(void)
301262
{
302263
IRDA_DEBUG(3, "%s()\n", __func__);
303264

304-
/* FIXME : This should be redundant, as pci_unregister_driver()
305-
* should call via_remove_one() on each device.
306-
* Jean II */
307-
via_ircc_clean();
308-
309265
/* Cleanup all instances of the driver */
310266
pci_unregister_driver (&via_driver);
311267
}
@@ -324,22 +280,20 @@ static const struct net_device_ops via_ircc_fir_ops = {
324280
};
325281

326282
/*
327-
* Function via_ircc_open (iobase, irq)
283+
* Function via_ircc_open(pdev, iobase, irq)
328284
*
329285
* Open driver instance
330286
*
331287
*/
332-
static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
288+
static __devinit int via_ircc_open(struct pci_dev *pdev, chipio_t * info,
289+
unsigned int id)
333290
{
334291
struct net_device *dev;
335292
struct via_ircc_cb *self;
336293
int err;
337294

338295
IRDA_DEBUG(3, "%s()\n", __func__);
339296

340-
if (i >= ARRAY_SIZE(dev_self))
341-
return -ENOMEM;
342-
343297
/* Allocate new instance of the driver */
344298
dev = alloc_irdadev(sizeof(struct via_ircc_cb));
345299
if (dev == NULL)
@@ -349,13 +303,8 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
349303
self->netdev = dev;
350304
spin_lock_init(&self->lock);
351305

352-
/* FIXME : We should store our driver instance in the PCI layer,
353-
* using pci_set_drvdata(), not in this array.
354-
* See vlsi_ir for details... - Jean II */
355-
/* FIXME : 'i' is always 0 (see via_init_one()) :-( - Jean II */
356-
/* Need to store self somewhere */
357-
dev_self[i] = self;
358-
self->index = i;
306+
pci_set_drvdata(pdev, self);
307+
359308
/* Initialize Resource */
360309
self->io.cfg_base = info->cfg_base;
361310
self->io.fir_base = info->fir_base;
@@ -463,25 +412,24 @@ static __devinit int via_ircc_open(int i, chipio_t * info, unsigned int id)
463412
err_out2:
464413
release_region(self->io.fir_base, self->io.fir_ext);
465414
err_out1:
415+
pci_set_drvdata(pdev, NULL);
466416
free_netdev(dev);
467-
dev_self[i] = NULL;
468417
return err;
469418
}
470419

471420
/*
472-
* Function via_ircc_close (self)
421+
* Function via_remove_one(pdev)
473422
*
474423
* Close driver instance
475424
*
476425
*/
477-
static int via_ircc_close(struct via_ircc_cb *self)
426+
static void __devexit via_remove_one(struct pci_dev *pdev)
478427
{
428+
struct via_ircc_cb *self = pci_get_drvdata(pdev);
479429
int iobase;
480430

481431
IRDA_DEBUG(3, "%s()\n", __func__);
482432

483-
IRDA_ASSERT(self != NULL, return -1;);
484-
485433
iobase = self->io.fir_base;
486434

487435
ResetChip(iobase, 5); //hardware reset.
@@ -498,11 +446,11 @@ static int via_ircc_close(struct via_ircc_cb *self)
498446
if (self->rx_buff.head)
499447
dma_free_coherent(NULL, self->rx_buff.truesize,
500448
self->rx_buff.head, self->rx_buff_dma);
501-
dev_self[self->index] = NULL;
449+
pci_set_drvdata(pdev, NULL);
502450

503451
free_netdev(self->netdev);
504452

505-
return 0;
453+
pci_disable_device(pdev);
506454
}
507455

508456
/*

0 commit comments

Comments
 (0)