[PATCH BUGFIX 25-rc1] Smack: Don't fail against Nulled sk sockets

2008-02-12 Thread Ahmed S. Darwish
Hi!,

Appropriately handle sockets with sk = NULL. This is usually the socket
case when starting kernel nfsd.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
Acked-by: Casey Schaufler [EMAIL PROTECTED]
Tested-by: Joerg Platte [EMAIL PROTECTED]
--

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 1c11e42..eb04278 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -701,7 +701,7 @@ static int smack_inode_getsecurity(const struct inode 
*inode,
return -EOPNOTSUPP;
 
sock = SOCKET_I(ip);
-   if (sock == NULL)
+   if (sock == NULL || sock-sk == NULL)
return -EOPNOTSUPP;
 
ssp = sock-sk-sk_security;
@@ -1280,10 +1280,12 @@ static void smack_to_secattr(char *smack, struct 
netlbl_lsm_secattr *nlsp)
  */
 static int smack_netlabel(struct sock *sk)
 {
-   struct socket_smack *ssp = sk-sk_security;
+   struct socket_smack *ssp;
struct netlbl_lsm_secattr secattr;
int rc = 0;
 
+   BUG_ON(sk == NULL);
+   ssp = sk-sk_security;
netlbl_secattr_init(secattr);
smack_to_secattr(ssp-smk_out, secattr);
if (secattr.flags != NETLBL_SECATTR_NONE)
@@ -1331,7 +1333,7 @@ static int smack_inode_setsecurity(struct inode *inode, 
const char *name,
return -EOPNOTSUPP;
 
sock = SOCKET_I(inode);
-   if (sock == NULL)
+   if (sock == NULL || sock-sk == NULL)
return -EOPNOTSUPP;
 
ssp = sock-sk-sk_security;
@@ -1362,7 +1364,7 @@ static int smack_inode_setsecurity(struct inode *inode, 
const char *name,
 static int smack_socket_post_create(struct socket *sock, int family,
int type, int protocol, int kern)
 {
-   if (family != PF_INET)
+   if (family != PF_INET || sock-sk == NULL)
return 0;
/*
 * Set the outbound netlbl.


Warm regards

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] net: tun/tap: fixed hw address handling

2007-03-26 Thread Ahmed S. Darwish
On Sun, Mar 25, 2007 at 01:29:29AM -0700, Brian Braunstein wrote:
 
 From: Brian Braunstein [EMAIL PROTECTED]
 

No need for this line. This line is used when you _forward_ another patch
from others. Signed-off-by is enough

 
 Signed-off-by: Brian Braunstein [EMAIL PROTECTED]
 
 ---
 
 Kernel Version: 2.6.20.4
 

It's always better to generate the patch against the latest -rc kernel.

 --- linux-2.6.20.4-ORIG/drivers/net/tun.c 2007-03-23 
 12:52:51.0 -0700
 +++ linux-2.6.20.4/drivers/net/tun.c  2007-03-25 00:44:20.0 -0700
 @@ -18,6 +18,10 @@
 /*
  *  Changes:
  *
 + *  Brian Braunstein [EMAIL PROTECTED] 2007/03/23
 + *Fixed hw address handling.  Now net_device.dev_addr is kept 
 consistent

Your mailer still wrap the long lines mistakenly as it did in the first
version of the patch.

Regards,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com

-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] net: tun/tap: fixed hw address handling

2007-03-26 Thread Ahmed S. Darwish
On Mon, Mar 26, 2007 at 10:55:11PM +0200, ahmed wrote:
 On Sun, Mar 25, 2007 at 01:29:29AM -0700, Brian Braunstein wrote:
  --- linux-2.6.20.4-ORIG/drivers/net/tun.c   2007-03-23 
  12:52:51.0 -0700
  +++ linux-2.6.20.4/drivers/net/tun.c2007-03-25 00:44:20.0 
  -0700
  @@ -18,6 +18,10 @@
  /*
   *  Changes:
   *
  + *  Brian Braunstein [EMAIL PROTECTED] 2007/03/23
  + *Fixed hw address handling.  Now net_device.dev_addr is kept 
  consistent
 
 Your mailer still wrap the long lines mistakenly as it did in the first
 version of the patch.
 

It seems a bug in my mutt mail reader (not a feature, it displays other 
mails long lines without wrapping), sorry.

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com

-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch 1/2] natsemi: Add support for using MII port with no PHY

2007-02-14 Thread Ahmed S. Darwish
On Wed, Feb 14, 2007 at 10:02:04AM +, Mark Brown wrote:

 Signed-Off-By: Mark Brown [EMAIL PROTECTED]
 
[...]
 - if (np-phy_addr_external == PHY_ADDR_NONE) {
 + /* If we're ignoring the PHY it doesn't matter if we can't
 +  * find one. */
 + if (!np-ignore_phy  np-phy_addr_external == PHY_ADDR_NONE) {
[...]
 + if (!np-ignore_phy) {
 + /* The link status field is latched: it remains low
 +  * after a temporary link failure until it's read. We
 +  * need the current link status, thus read twice.
 +  */
 + mdio_read(dev, MII_BMSR);
 + bmsr = mdio_read(dev, MII_BMSR);
[...]
   /*
 +  * If we're ignoring the PHY then autoneg and the internal
 +  * transciever are really not going to work so don't let the
 +  * user select them.
 +  */
 + if (np-ignore_phy  (ecmd-autoneg == AUTONEG_ENABLE ||

A trivial comment actually, Is there a point to write multi-line comments 
in two different formats ?

Thanks,

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate

2007-02-06 Thread Ahmed S. Darwish
On Mon, Feb 05, 2007 at 11:17:09PM +0300, Alexey Dobriyan wrote:
 On Mon, Feb 05, 2007 at 07:00:44PM +0200, Ahmed S. Darwish wrote:
  A trivial patch to use ARRAY_SIZE macro.
 
 You're supposed to remove it ans use ARRAY_SIZE where old macro is used.
 
  --- a/drivers/net/wireless/wavelan.p.h
  +++ b/drivers/net/wireless/wavelan.p.h
  @@ -450,7 +450,7 @@ static const char   *version= wavelan.c : 
  v24 (SMP + wireless extensions) 11/12/
   #defineWATCHDOG_JIFFIES(512*HZ/100)
 
   /* Macro to get the number of elements in an array */
  -#defineNELS(a) (sizeof(a) / sizeof(a[0]))
  +#defineNELS(a) ARRAY_SIZE(a)

Ooh, how dumb the original patch is :). Thanks, here's the modified patch.

A patch to use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 24221e4..2aa3c76 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -28,7 +28,7 @@
  */
 static u8 wv_irq_to_psa(int irq)
 {
-   if (irq  0 || irq = NELS(irqvals))
+   if (irq  0 || irq = ARRAY_SIZE(irqvals))
return 0;
 
return irqvals[irq];
@@ -42,7 +42,7 @@ static int __init wv_psa_to_irq(u8 irqval)
 {
int irq;
 
-   for (irq = 0; irq  NELS(irqvals); irq++)
+   for (irq = 0; irq  ARRAY_SIZE(irqvals); irq++)
if (irqvals[irq] == irqval)
return irq;
 
@@ -1695,7 +1695,7 @@ static int wv_frequency_list(unsigned long ioaddr,
/* I/O port of the card */
/* Look in the table if the frequency is allowed */
if (table[9 - (freq / 16)]  (1  (freq % 16))) {
/* Compute approximate channel number */
-   while ((c  NELS(channel_bands)) 
+   while ((c  ARRAY_SIZE(channel_bands)) 
(((channel_bands[c]  1) - 24)  freq)) 
c++;
list[i].i = c;  /* Set the list index */
@@ -4269,7 +4269,7 @@ struct net_device * __init wavelan_probe(int unit)
printk(KERN_DEBUG %s: -wavelan_probe()\n, dev-name);
 #endif
} else { /* Scan all possible addresses of the WaveLAN hardware. */
-   for (i = 0; i  NELS(iobase); i++) {
+   for (i = 0; i  ARRAY_SIZE(iobase); i++) {
dev-irq = def_irq;
if (wavelan_config(dev, iobase[i]) == 0) {
 #ifdef DEBUG_CALLBACK_TRACE
@@ -4280,7 +4280,7 @@ struct net_device * __init wavelan_probe(int unit)
break;
}
}
-   if (i == NELS(iobase))
+   if (i == ARRAY_SIZE(iobase))
r = -ENODEV;
}
if (r) 
@@ -4327,14 +4327,14 @@ int __init init_module(void)
 #endif
 
/* Copy the basic set of address to be probed. */
-   for (i = 0; i  NELS(iobase); i++)
+   for (i = 0; i  ARRAY_SIZE(iobase); i++)
io[i] = iobase[i];
}
 
 
/* Loop on all possible base addresses. */
i = -1;
-   while ((io[++i] != 0)  (i  NELS(io))) {
+   while ((io[++i] != 0)  (i  ARRAY_SIZE(io))) {
struct net_device *dev = alloc_etherdev(sizeof(net_local));
if (!dev)
break;
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe24281 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -449,9 +449,6 @@ static const char   *version= wavelan.c : v24 (SMP 
+ wireless extensions) 11/12/
 /* Watchdog temporisation */
 #defineWATCHDOG_JIFFIES(512*HZ/100)
 
-/* Macro to get the number of elements in an array */
-#defineNELS(a) (sizeof(a) / sizeof(a[0]))
-
 /*  PRIVATE IOCTL  */
 
 #define SIOCSIPQTHRSIOCIWFIRSTPRIV /* Set quality threshold */

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate

2007-02-06 Thread Ahmed S. Darwish
On Mon, Feb 05, 2007 at 12:31:26PM -0800, Auke Kok wrote:
 Alexey Dobriyan wrote:
 On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
 A patch to use ARRAY_SIZE macro already defined in kernel.h.
 
 Remove it and use ARRAY_SIZE instead.
 
 --- a/drivers/net/ixgb/ixgb_param.c
 +++ b/drivers/net/ixgb/ixgb_param.c
 @@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option 
 *opt)
 return -1;
  }
  
 -#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
 +#define LIST_LEN(l) ARRAY_SIZE(l)
 
 yes, well spotted. Please change line 338 in this file to read:
 
  .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
 
 instead, so you can remove the LIST_LEN macro completely.
 
Thanks, Here's the new patch.

Use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..c38ce73 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,8 +245,6 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
-
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters
  * @adapter: board private structure
@@ -335,7 +333,7 @@ ixgb_check_options(struct ixgb_adapter *adapter)
.name = Flow Control,
.err  = reading default settings from EEPROM,
.def  = ixgb_fc_tx_pause,
-   .arg  = { .l = { .nr = LIST_LEN(fc_list),
+   .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
 .p = fc_list }}
};


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate

2007-02-06 Thread Ahmed S. Darwish
On Mon, Feb 05, 2007 at 11:22:06PM +0300, Alexey Dobriyan wrote:
 On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
  A patch to use ARRAY_SIZE macro already defined in kernel.h.
 
 OK, but checks you're changing are strange. idx there is signed so
 
   BUG_ON(idx  0 || idx  ARRAY_SIZE());
 
 should be more appropriate.

It's just a janitor patch. I don't like to mess with code logic in such
kind of patches (to minimize errors and because I can't find time to
understand all affected files since they are scattered allover the tree).

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers

2007-02-05 Thread Ahmed S. Darwish
Hi all,

Follows is a sereis of patches to use ARRAY_SIZE macro in drivers/net. 
Patches are sent separately according to their maintaners as replies to 
this thread.

 apne.c |2 +-
 arm/am79c961a.c|2 +-
 atarilance.c   |2 +-
 cs89x0.c   |6 +++---
 e1000/e1000_ethtool.c  |2 +-
 fec_8xx/fec_mii.c  |4 ++--
 ibm_emac/ibm_emac_debug.c  |8 
 irda/actisys-sir.c |3 ++-
 ixgb/ixgb_param.c  |2 +-
 lp486e.c   |2 +-
 ne-h8300.c |2 +-
 ne.c   |2 +-
 ne2.c  |2 +-
 ne2k-pci.c |2 +-
 netxen/netxen_nic_hw.c |2 +-
 pcmcia/axnet_cs.c  |2 +-
 pcmcia/pcnet_cs.c  |2 +-
 sk98lin/skgemib.c  |4 +++-
 sk98lin/skgesirq.c |3 ++-
 skfp/smt.c |3 ++-
 skfp/srf.c |6 --
 wireless/airo.c|4 ++--
 wireless/hostap/hostap.h   |3 ++-
 wireless/ipw2100.c |   14 ++
 wireless/prism54/oid_mgt.c |4 +++-
 wireless/wavelan.p.h   |2 +-
 zorro8390.c|2 +-
 27 files changed, 50 insertions(+), 42 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch is compile tested.

diff --git a/drivers/net/e1000/e1000_ethtool.c 
b/drivers/net/e1000/e1000_ethtool.c
index fb96c87..d21706e 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -746,7 +746,7 @@ err_setup:
uint32_t pat, value;   \
uint32_t test[] =  \
{0x5A5A5A5A, 0xA5A5A5A5, 0x, 0x};  \
-   for (pat = 0; pat  sizeof(test)/sizeof(test[0]); pat++) {  
\
+   for (pat = 0; pat  ARRAY_SIZE(test); pat++) {  \
E1000_WRITE_REG(adapter-hw, R, (test[pat]  W)); \
value = E1000_READ_REG(adapter-hw, R);   \
if (value != (test[pat]  W  M)) { 
\

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
[PATCH 01/02] is compile tested.
[PATCH 02/02] isn't compile tested cause of missing hardware.

diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 4612f71..d48196c 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -806,7 +806,7 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int 
modular)
i = cs8900_irq_map[0];
 #else
/* Translate the IRQ using the IRQ mapping table. */
-   if (i = 
sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+   if (i = ARRAY_SIZE(cs8900_irq_map))
printk(\ncs89x0: invalid ISA interrupt number 
%d\n, i);
else
i = cs8900_irq_map[i];
@@ -1248,11 +1248,11 @@ write_irq(struct net_device *dev, int chip_type, int 
irq)
 
if (chip_type == CS8900) {
/* Search the mapping table for the corresponding IRQ pin. */
-   for (i = 0; i != 
sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]); i++)
+   for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++)
if (cs8900_irq_map[i] == irq)
break;
/* Not found */
-   if (i == sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+   if (i == ARRAY_SIZE(cs8900_irq_map))
i = 3;
writereg(dev, PP_CS8900_ISAINT, i);
} else {
diff --git a/drivers/net/irda/actisys-sir.c b/drivers/net/irda/actisys-sir.c
index 9715ab5..84d7bb0 100644
--- a/drivers/net/irda/actisys-sir.c
+++ b/drivers/net/irda/actisys-sir.c
@@ -43,6 +43,7 @@
 #include linux/module.h
 #include linux/delay.h
 #include linux/init.h
+#include linux/kernel.h
 
 #include net/irda/irda.h
 
@@ -67,7 +68,7 @@ static int actisys_reset(struct sir_dev *);
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
+#define MAX_SPEEDS ARRAY_SIZE(baud_rates)
 
 static struct dongle_driver act220l = {
.owner  = THIS_MODULE,
diff --git a/drivers/net/lp486e.c b/drivers/net/lp486e.c
index 177c502..4b016aa 100644
--- a/drivers/net/lp486e.c
+++ b/drivers/net/lp486e.c
@@ -515,7 +515,7 @@ CLEAR_INT(void) {
outb(0, IOADDR+8);
 }
 
-#define SIZE(x)(sizeof(x)/sizeof((x)[0]))
+#define SIZE(x)ARRAY_SIZE(x)
 
 #if 0
 /* selftest or dump */
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index a5c4199..7081d08 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -379,7 +379,7 @@ static int __init ne_probe1(struct net_device *dev, int 
ioaddr)
{E8390_RREAD+E8390_START, E8390_CMD},
};
 
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++)
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++)
outb_p(program_seq[i].value, ioaddr + 
program_seq[i].offset);
 
}
diff --git a/drivers/net/ne2.c b/drivers/net/ne2.c
index 089b5bb..c6c2a91 100644
--- a/drivers/net/ne2.c
+++ b/drivers/net/ne2.c
@@ -432,7 +432,7 @@ static int __init ne2_probe1(struct net_device *dev, int 
slot)
{E8390_RREAD+E8390_START, E8390_CMD},
};
 
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++)
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++)
outb_p(program_seq[i].value, base_addr +
program_seq[i].offset);
 
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index 589785d..6bafdda 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -309,7 +309,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev 
*pdev,
{0x00,  EN0_RSARHI},
{E8390_RREAD+E8390_START, E8390_CMD},
};
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++)
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++)
outb(program_seq[i].value, ioaddr + 
program_seq[i].offset);
 
}
diff --git a/drivers/net/netxen/netxen_nic_hw.c 
b/drivers/net/netxen/netxen_nic_hw.c
index f263232..7f93c08 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -395,7 +395,7 @@ int netxen_is_flash_supported(struct netxen_adapter 
*adapter)
/* if the flash size less than 4Mb, make huge war cry and die */
for (j = 1; j  4; j++) {
addr = j * NETXEN_NIC_WINDOW_MARGIN;
-   for (i = 0; i  (sizeof(locs) / sizeof(locs[0])); i++) {
+   for (i = 0; i  ARRAY_SIZE(locs); i

[PATCH 2.6.20] ipw2100: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch is compile tested.

diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b85857a..a9d944a 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -2888,7 +2888,7 @@ static int __ipw2100_tx_process(struct ipw2100_priv *priv)
 
 #ifdef CONFIG_IPW2100_DEBUG
if (packet-info.c_struct.cmd-host_command_reg 
-   sizeof(command_types) / sizeof(*command_types))
+   ARRAY_SIZE(command_types))
IPW_DEBUG_TX(Command '%s (%d)' processed: %d.\n,
 command_types[packet-info.c_struct.cmd-
   host_command_reg],
@@ -3736,7 +3736,7 @@ static ssize_t show_registers(struct device *d, struct 
device_attribute *attr,
 
out += sprintf(out, %30s [Address ] : Hex\n, Register);
 
-   for (i = 0; i  (sizeof(hw_data) / sizeof(*hw_data)); i++) {
+   for (i = 0; i  ARRAY_SIZE(hw_data); i++) {
read_register(dev, hw_data[i].addr, val);
out += sprintf(out, %30s [%08X] : %08X\n,
   hw_data[i].name, hw_data[i].addr, val);
@@ -3757,7 +3757,7 @@ static ssize_t show_hardware(struct device *d, struct 
device_attribute *attr,
 
out += sprintf(out, %30s [Address ] : Hex\n, NIC entry);
 
-   for (i = 0; i  (sizeof(nic_data) / sizeof(*nic_data)); i++) {
+   for (i = 0; i  ARRAY_SIZE(nic_data); i++) {
u8 tmp8;
u16 tmp16;
u32 tmp32;
@@ -3894,13 +3894,11 @@ static ssize_t show_ordinals(struct device *d, struct 
device_attribute *attr,
if (priv-status  STATUS_RF_KILL_MASK)
return 0;
 
-   if (loop = sizeof(ord_data) / sizeof(*ord_data))
+   if (loop = ARRAY_SIZE(ord_data))
loop = 0;
 
/* sysfs provides us PAGE_SIZE buffer */
-   while (len  PAGE_SIZE - 128 
-  loop  (sizeof(ord_data) / sizeof(*ord_data))) {
-
+   while (len  PAGE_SIZE - 128  loop  ARRAY_SIZE(ord_data)) {
val_len = sizeof(u32);
 
if (ipw2100_get_ordinal(priv, ord_data[loop].index, val,
@@ -6589,7 +6587,7 @@ static const long ipw2100_rates_11b[] = {
1100
 };
 
-#define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
+#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
 
 static int ipw2100_wx_get_name(struct net_device *dev,
   struct iw_request_info *info,


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch isn't compile-tested due to missing hardware.

diff --git a/drivers/net/apne.c b/drivers/net/apne.c
index 9541911..8806151 100644
--- a/drivers/net/apne.c
+++ b/drivers/net/apne.c
@@ -247,7 +247,7 @@ static int __init apne_probe1(struct net_device *dev, int 
ioaddr)
{0x00,  NE_EN0_RSARHI},
{E8390_RREAD+E8390_START, NE_CMD},
};
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++) {
outb(program_seq[i].value, ioaddr + program_seq[i].offset);
}
 
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index ddd12d4..200cbc0 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -414,7 +414,7 @@ static void am79c961_setmulticastlist (struct net_device 
*dev)
/*
 * Update the multicast hash table
 */
-   for (i = 0; i  sizeof(multi_hash) / sizeof(multi_hash[0]); i++)
+   for (i = 0; i  ARRAY_SIZE(multi_hash); i++)
write_rreg(dev-base_addr, i + LADRL, multi_hash[i]);
 
/*
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index 7e37ac8..ef18428 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -263,7 +263,7 @@ struct lance_addr {
   
(highest byte stripped) */
 };
 
-#defineN_LANCE_ADDR
(sizeof(lance_addr_list)/sizeof(*lance_addr_list))
+#defineN_LANCE_ADDRARRAY_SIZE(lance_addr_list)
 
 
 /* Definitions for the Lance */
diff --git a/drivers/net/fec_8xx/fec_mii.c b/drivers/net/fec_8xx/fec_mii.c
index d3c16b8..1fc2b43 100644
--- a/drivers/net/fec_8xx/fec_mii.c
+++ b/drivers/net/fec_8xx/fec_mii.c
@@ -310,12 +310,12 @@ int fec_mii_phy_id_detect(struct net_device *dev)
return -1;
}
 
-   for (i = 0, phy = phy_info; i  sizeof(phy_info) / sizeof(phy_info[0]);
+   for (i = 0, phy = phy_info; i  ARRAY_SIZE(phy_info));
 i++, phy++)
if (phy-id == (phy_hwid  4) || phy-id == 0)
break;
 
-   if (i = sizeof(phy_info) / sizeof(phy_info[0])) {
+   if (i = ARRAY_SIZE(phy_info)) {
printk(KERN_ERR DRV_MODULE_NAME
   : %s PHY id 0x%08x is not supported!\n,
   dev-name, phy_hwid);
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index 38fd525..7599d77 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -259,7 +259,7 @@ static int __init ne_probe1(struct net_device *dev, int 
ioaddr)
{E8390_RREAD+E8390_START, E8390_CMD},
};
 
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++)
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++)
outb_p(program_seq[i].value, ioaddr + 
program_seq[i].offset);
 
}
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c
index d85e2ea..29f9750 100644
--- a/drivers/net/zorro8390.c
+++ b/drivers/net/zorro8390.c
@@ -191,7 +191,7 @@ static int __devinit zorro8390_init(struct net_device *dev,
{0x00,  NE_EN0_RSARHI},
{E8390_RREAD+E8390_START, NE_CMD},
};
-   for (i = 0; i  sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+   for (i = 0; i  ARRAY_SIZE(program_seq); i++) {
z_writeb(program_seq[i].value, ioaddr + program_seq[i].offset);
}
 }


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] misc-wireless: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous wireless drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch is compile tested.

diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 44a2270..4ad910b 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1623,7 +1623,7 @@ static void emmh32_setseed(emmh32_context *context, u8 
*pkey, int keylen,
 
crypto_cipher_setkey(tfm, pkey, 16);
counter = 0;
-   for (i = 0; i  (sizeof(context-coeff)/sizeof(context-coeff[0])); ) {
+   for (i = 0; i  ARRAY_SIZE(context-coeff); ) {
aes_counter[15] = (u8)(counter  0);
aes_counter[14] = (u8)(counter  8);
aes_counter[13] = (u8)(counter  16);
@@ -1632,7 +1632,7 @@ static void emmh32_setseed(emmh32_context *context, u8 
*pkey, int keylen,
memcpy (plain, aes_counter, 16);
crypto_cipher_encrypt_one(tfm, plain, plain);
cipher = plain;
-   for (j=0; (j16)  (i 
(sizeof(context-coeff)/sizeof(context-coeff[0]))); ) {
+   for (j = 0; (j  16)  (i  ARRAY_SIZE(context-coeff)); ) {
context-coeff[i++] = ntohl(*(u32 *)cipher[j]);
j += 4;
}
diff --git a/drivers/net/wireless/prism54/oid_mgt.c 
b/drivers/net/wireless/prism54/oid_mgt.c
index e6cf9df..4278032 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -16,6 +16,8 @@
  *
  */
 
+#include linux/kernel.h
+
 #include prismcompat.h
 #include islpci_dev.h
 #include islpci_mgt.h
@@ -692,7 +694,7 @@ mgt_update_addr(islpci_private *priv)
return ret;
 }
 
-#define VEC_SIZE(a) (sizeof(a)/sizeof(a[0]))
+#define VEC_SIZE(a) ARRAY_SIZE(a)
 
 int
 mgt_commit(islpci_private *priv)



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] hostap: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A patch to use ARRAY_SIZE macro in the Host AP wireless driver.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch is compile tested.

diff --git a/drivers/net/wireless/hostap/hostap.h 
b/drivers/net/wireless/hostap/hostap.h
index e89c890..ef37a75 100644
--- a/drivers/net/wireless/hostap/hostap.h
+++ b/drivers/net/wireless/hostap/hostap.h
@@ -2,13 +2,14 @@
 #define HOSTAP_H
 
 #include linux/ethtool.h
+#include linux/kernel.h
 
 #include hostap_wlan.h
 #include hostap_ap.h
 
 static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  2447, 2452, 2457, 2462, 2467, 2472, 2484 };
-#define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
+#define FREQ_COUNT ARRAY_SIZE(freq_list)
 
 /* hostap.c */
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..26031fe 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
+#define LIST_LEN(l) ARRAY_SIZE(l)
 
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A trivial patch to use ARRAY_SIZE macro.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe12c77 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -450,7 +450,7 @@ static const char   *version= wavelan.c : v24 (SMP 
+ wireless extensions) 11/12/
 #defineWATCHDOG_JIFFIES(512*HZ/100)
 
 /* Macro to get the number of elements in an array */
-#defineNELS(a) (sizeof(a) / sizeof(a[0]))
+#defineNELS(a) ARRAY_SIZE(a)
 
 /*  PRIVATE IOCTL  */
 



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate

2007-02-05 Thread Ahmed S. Darwish
Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
Patch isn't compile-tested cause I don't have the needed hardware.

diff --git a/drivers/net/ibm_emac/ibm_emac_debug.c 
b/drivers/net/ibm_emac/ibm_emac_debug.c
index 92f970d..1f70906 100644
--- a/drivers/net/ibm_emac/ibm_emac_debug.c
+++ b/drivers/net/ibm_emac/ibm_emac_debug.c
@@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private 
*dev)
 {
unsigned long flags;
 
-   if (idx = sizeof(__emacs) / sizeof(__emacs[0])) {
+   if (idx = ARRAY_SIZE(__emacs)) {
printk(KERN_WARNING
   invalid index %d when registering EMAC for debugging\n,
   idx);
@@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
 {
unsigned long flags;
 
-   if (idx = sizeof(__mals) / sizeof(__mals[0])) {
+   if (idx = ARRAY_SIZE(__mals)) {
printk(KERN_WARNING
   invalid index %d when registering MAL for debugging\n,
   idx);
@@ -167,11 +167,11 @@ void emac_dbg_dump_all(void)
 
local_irq_save(flags);
 
-   for (i = 0; i  sizeof(__mals) / sizeof(__mals[0]); ++i)
+   for (i = 0; i  ARRAY_SIZE(__mals); ++i)
if (__mals[i])
emac_mal_dump(__mals[i]);
 
-   for (i = 0; i  sizeof(__emacs) / sizeof(__emacs[0]); ++i)
+   for (i = 0; i  ARRAY_SIZE(__emacs); ++i)
if (__emacs[i])
emac_mac_dump(i, __emacs[i]);
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups

2007-01-07 Thread Ahmed S. Darwish
On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:
  From: Ahmed S. Darwish [mailto:[EMAIL PROTECTED]
  
  Hi,
  A kmalloc casting cleanup patch.
  Signed-off-by: Ahmed Darwish [EMAIL PROTECTED]

[..]

  -   (u32) (kmalloc((u32) (length + align),
  -   GFP_KERNEL));
  +   kmalloc((u32) (length + align), GFP_KERNEL);
  +
  if (ugeth-tx_bd_ring_offset[j] != 0)
  ugeth-p_tx_bd_ring[j] =

[..]

  -   (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
  +   kmalloc((u32) (length + align), GFP_KERNEL);
 
 NACK about the 2 clean-ups above.  Cast from pointer to integer is
 required here.

Are the casts from pointer to integer just needed to suppress gcc 
warnings or there's something technically important about them ?

I'll send the modified patch without the NACKed parts in minutes ..

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups

2007-01-07 Thread Ahmed S. Darwish
On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:

 NACK about the 2 clean-ups above.  Cast from pointer to integer is
 required here.
 

Hi, here's the modified patch.

A patch to switch kmalloc to kzalloc and clean some redundant kmalloc
casts.

Signed-off-by: Ahmed S. Darwish [EMAIL PROTECTED]
---
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150..0f58f5f 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private 
*ugeth)
/* Init Tx bds */
for (j = 0; j  ug_info-numQueuesTx; j++) {
/* Setup the skbuff rings */
-   ugeth-tx_skbuff[j] =
-   (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-  ugeth-ug_info-bdRingLenTx[j],
-  GFP_KERNEL);
+   ugeth-tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+ ugeth-ug_info-bdRingLenTx[j],
+ GFP_KERNEL);
 
if (ugeth-tx_skbuff[j] == NULL) {
ugeth_err(%s: Could not allocate tx_skbuff,
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private 
*ugeth)
/* Init Rx bds */
for (j = 0; j  ug_info-numQueuesRx; j++) {
/* Setup the skbuff rings */
-   ugeth-rx_skbuff[j] =
-   (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-  ugeth-ug_info-bdRingLenRx[j],
-  GFP_KERNEL);
+   ugeth-rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+ ugeth-ug_info-bdRingLenRx[j],
+ GFP_KERNEL);
 
if (ugeth-rx_skbuff[j] == NULL) {
ugeth_err(%s: Could not allocate rx_skbuff,
@@ -3450,19 +3448,16 @@ static int ucc_geth_startup(struct ucc_geth_private 
*ugeth)
 * resource.
 * This shadow structure keeps a copy of what was done so that the
 * allocated resources can be released when the channel is freed.
+* *p_init_enet_param_shadow is zeroed by kzalloc
 */
-   if (!(ugeth-p_init_enet_param_shadow =
-(struct ucc_geth_init_pram *) kmalloc(sizeof(struct 
ucc_geth_init_pram),
- GFP_KERNEL))) {
+   if (!(ugeth-p_init_enet_param_shadow = 
+ kzalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
ugeth_err
(%s: Can not allocate memory for
 p_UccInitEnetParamShadows., __FUNCTION__);
ucc_geth_memclean(ugeth);
return -ENOMEM;
}
-   /* Zero out *p_init_enet_param_shadow */
-   memset((char *)ugeth-p_init_enet_param_shadow,
-  0, sizeof(struct ucc_geth_init_pram));
 
/* Fill shadow InitEnet command parameter structure */
 


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html