All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mwl8k: use integral index instead of pointer for driver_data
@ 2009-11-06 21:42 John W. Linville
  2009-11-06 21:56 ` Michael Buesch
  0 siblings, 1 reply; 3+ messages in thread
From: John W. Linville @ 2009-11-06 21:42 UTC (permalink / raw)
  To: linux-wireless; +Cc: Lennert Buytenhek, John W. Linville

Use of an integral index makes adding new device IDs through sysfs more
practical.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
---
 drivers/net/wireless/mwl8k.c |   47 ++++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index 9fde17b..2ebfee4 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -3308,34 +3308,33 @@ static void mwl8k_finalize_join_worker(struct work_struct *work)
 	priv->beacon_skb = NULL;
 }
 
-static struct mwl8k_device_info di_8366 = {
-	.part_name	= "88w8366",
-	.helper_image	= "mwl8k/helper_8366.fw",
-	.fw_image	= "mwl8k/fmimage_8366.fw",
-	.rxd_ops	= &rxd_8366_ops,
-	.modes		= 0,
+enum {
+	MWL8687 = 0,
+	MWL8366,
 };
 
-static struct mwl8k_device_info di_8687 = {
-	.part_name	= "88w8687",
-	.helper_image	= "mwl8k/helper_8687.fw",
-	.fw_image	= "mwl8k/fmimage_8687.fw",
-	.rxd_ops	= &rxd_8687_ops,
-	.modes		= BIT(NL80211_IFTYPE_STATION),
+static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
+	{
+		.part_name	= "88w8687",
+		.helper_image	= "mwl8k/helper_8687.fw",
+		.fw_image	= "mwl8k/fmimage_8687.fw",
+		.rxd_ops	= &rxd_8687_ops,
+		.modes		= BIT(NL80211_IFTYPE_STATION),
+	},
+	{
+		.part_name	= "88w8366",
+		.helper_image	= "mwl8k/helper_8366.fw",
+		.fw_image	= "mwl8k/fmimage_8366.fw",
+		.rxd_ops	= &rxd_8366_ops,
+		.modes		= 0,
+	},
 };
 
 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
-	{
-		PCI_VDEVICE(MARVELL, 0x2a2b),
-		.driver_data = (unsigned long)&di_8687,
-	}, {
-		PCI_VDEVICE(MARVELL, 0x2a30),
-		.driver_data = (unsigned long)&di_8687,
-	}, {
-		PCI_VDEVICE(MARVELL, 0x2a40),
-		.driver_data = (unsigned long)&di_8366,
-	}, {
-	},
+	{ PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
+	{ PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
+	{ PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
+	{ },
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
@@ -3379,7 +3378,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	priv = hw->priv;
 	priv->hw = hw;
 	priv->pdev = pdev;
-	priv->device_info = (void *)id->driver_data;
+	priv->device_info = &mwl8k_info_tbl[id->driver_data];
 	priv->rxd_ops = priv->device_info->rxd_ops;
 	priv->sniffer_enabled = false;
 	priv->wmm_enabled = false;
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mwl8k: use integral index instead of pointer for driver_data
  2009-11-06 21:42 [PATCH] mwl8k: use integral index instead of pointer for driver_data John W. Linville
@ 2009-11-06 21:56 ` Michael Buesch
  2009-11-06 22:01   ` Michael Buesch
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Buesch @ 2009-11-06 21:56 UTC (permalink / raw)
  To: John W. Linville; +Cc: linux-wireless, Lennert Buytenhek

On Friday 06 November 2009 22:42:07 John W. Linville wrote:
> @@ -3379,7 +3378,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
>  	priv = hw->priv;
>  	priv->hw = hw;
>  	priv->pdev = pdev;
> -	priv->device_info = (void *)id->driver_data;
> +	priv->device_info = &mwl8k_info_tbl[id->driver_data];
>  	priv->rxd_ops = priv->device_info->rxd_ops;
>  	priv->sniffer_enabled = false;
>  	priv->wmm_enabled = false;

What about a sanity check for id->driver_data on the array range? Otherwise one could crash
the kernel with sysfs/new_id by accident, as far as I can tell.

-- 
Greetings, Michael.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mwl8k: use integral index instead of pointer for driver_data
  2009-11-06 21:56 ` Michael Buesch
@ 2009-11-06 22:01   ` Michael Buesch
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Buesch @ 2009-11-06 22:01 UTC (permalink / raw)
  To: John W. Linville; +Cc: linux-wireless, Lennert Buytenhek

On Friday 06 November 2009 22:56:59 Michael Buesch wrote:
> On Friday 06 November 2009 22:42:07 John W. Linville wrote:
> > @@ -3379,7 +3378,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
> >  	priv = hw->priv;
> >  	priv->hw = hw;
> >  	priv->pdev = pdev;
> > -	priv->device_info = (void *)id->driver_data;
> > +	priv->device_info = &mwl8k_info_tbl[id->driver_data];
> >  	priv->rxd_ops = priv->device_info->rxd_ops;
> >  	priv->sniffer_enabled = false;
> >  	priv->wmm_enabled = false;
> 
> What about a sanity check for id->driver_data on the array range? Otherwise one could crash
> the kernel with sysfs/new_id by accident, as far as I can tell.
> 

Ok docs say that:
> Note that driver_data must match the value used by any of the pci_device_id
> entries defined in the driver. 

So ignore me.

-- 
Greetings, Michael.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-06 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-06 21:42 [PATCH] mwl8k: use integral index instead of pointer for driver_data John W. Linville
2009-11-06 21:56 ` Michael Buesch
2009-11-06 22:01   ` Michael Buesch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.