Commit 4955a5c8 authored by Randy Dunlap's avatar Randy Dunlap Committed by James Bottomley

[PATCH] reduce stack in qlogicfc.c

This is a start on reducing the stack usage in qlogicfc.c::
isp2x00_make_portdb().  I think that the stack reduction portion
of it is fine, but I'm concerned about the function returning
early due to kmalloc() failure, without making the port database.

[reduces stack from 0xc38 to 0x34 bytes (P4 UP, gcc 2.96)]

Can anyone suggest way(s) to have the isp2x00_make_portdb() function
called over and over again until it gets its job done?
Or does anyone even still use this driver?
parent 16b7fc66
...@@ -836,14 +836,22 @@ static int isp2x00_make_portdb(struct Scsi_Host *host) ...@@ -836,14 +836,22 @@ static int isp2x00_make_portdb(struct Scsi_Host *host)
short param[8]; short param[8];
int i, j; int i, j;
struct id_name_map temp[QLOGICFC_MAX_ID + 1]; struct id_name_map *map; /* base of array [QLOGICFC_MAX_ID + 1] */
struct id_name_map *mapx; /* array entry pointer */
struct isp2x00_hostdata *hostdata; struct isp2x00_hostdata *hostdata;
isp2x00_disable_irqs(host);
memset(temp, 0, sizeof(temp));
hostdata = (struct isp2x00_hostdata *) host->hostdata; hostdata = (struct isp2x00_hostdata *) host->hostdata;
map = kmalloc((QLOGICFC_MAX_ID + 1) * sizeof(struct id_name_map), GFP_ATOMIC);
if (!map) {
printk("qlogicfc%d : error getting memory -- cannot make port database.\n",
hostdata->host_id);
goto fini;
}
memset(map, 0, (QLOGICFC_MAX_ID + 1) * sizeof(struct id_name_map));
isp2x00_disable_irqs(host);
#if ISP2x00_FABRIC #if ISP2x00_FABRIC
for (i = 0x81; i < QLOGICFC_MAX_ID; i++) { for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
param[0] = MBOX_PORT_LOGOUT; param[0] = MBOX_PORT_LOGOUT;
...@@ -868,72 +876,74 @@ static int isp2x00_make_portdb(struct Scsi_Host *host) ...@@ -868,72 +876,74 @@ static int isp2x00_make_portdb(struct Scsi_Host *host)
if (param[0] == MBOX_COMMAND_COMPLETE) { if (param[0] == MBOX_COMMAND_COMPLETE) {
hostdata->port_id = ((u_int) param[3]) << 16; hostdata->port_id = ((u_int) param[3]) << 16;
hostdata->port_id |= param[2]; hostdata->port_id |= param[2];
temp[0].loop_id = param[1]; map->loop_id = param[1];
temp[0].wwn = hostdata->wwn; map->wwn = hostdata->wwn;
} }
else { else {
printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id); printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id);
} }
for (i = 0; i <=QLOGICFC_MAX_ID; i++) for (i = 0, mapx = map; i <= QLOGICFC_MAX_ID; i++, mapx++)
temp[i].loop_id = temp[0].loop_id; mapx->loop_id = map->loop_id;
for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) { for (i = 0, j = 1, mapx = map + 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
param[0] = MBOX_GET_PORT_NAME; param[0] = MBOX_GET_PORT_NAME;
param[1] = (i << 8) & 0xff00; param[1] = (i << 8) & 0xff00;
isp2x00_mbox_command(host, param); isp2x00_mbox_command(host, param);
if (param[0] == MBOX_COMMAND_COMPLETE) { if (param[0] == MBOX_COMMAND_COMPLETE) {
temp[j].loop_id = i; mapx->loop_id = i;
temp[j].wwn = ((u64) (param[2] & 0xff)) << 56; mapx->wwn = ((u64) (param[2] & 0xff)) << 56;
temp[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48; mapx->wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
temp[j].wwn |= ((u64) (param[3] & 0xff)) << 40; mapx->wwn |= ((u64) (param[3] & 0xff)) << 40;
temp[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32; mapx->wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
temp[j].wwn |= ((u64) (param[6] & 0xff)) << 24; mapx->wwn |= ((u64) (param[6] & 0xff)) << 24;
temp[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16; mapx->wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
temp[j].wwn |= ((u64) (param[7] & 0xff)) << 8; mapx->wwn |= ((u64) (param[7] & 0xff)) << 8;
temp[j].wwn |= ((u64) ((param[7] >> 8) & 0xff)); mapx->wwn |= ((u64) ((param[7] >> 8) & 0xff));
j++; j++;
mapx++;
} }
} }
#if ISP2x00_FABRIC #if ISP2x00_FABRIC
isp2x00_init_fabric(host, temp, j); isp2x00_init_fabric(host, map, j);
#endif #endif
for (i = 0; i <= QLOGICFC_MAX_ID; i++) { for (i = 0, mapx = map; i <= QLOGICFC_MAX_ID; i++, mapx++) {
if (temp[i].wwn != hostdata->port_db[i].wwn) { struct id_name_map *tmap; /* second array entry pointer */
for (j = 0; j <= QLOGICFC_MAX_ID; j++) { if (mapx->wwn != hostdata->port_db[i].wwn) {
if (temp[j].wwn == hostdata->port_db[i].wwn) { for (j = 0, tmap = map; j <= QLOGICFC_MAX_ID; j++, tmap++) {
hostdata->port_db[i].loop_id = temp[j].loop_id; if (tmap->wwn == hostdata->port_db[i].wwn) {
hostdata->port_db[i].loop_id = tmap->loop_id;
break; break;
} }
} }
if (j == QLOGICFC_MAX_ID + 1) if (j == QLOGICFC_MAX_ID + 1)
hostdata->port_db[i].loop_id = temp[0].loop_id; hostdata->port_db[i].loop_id = map->loop_id;
for (j = 0; j <= QLOGICFC_MAX_ID; j++) { for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
if (hostdata->port_db[j].wwn == temp[i].wwn || !hostdata->port_db[j].wwn) { if (hostdata->port_db[j].wwn == mapx->wwn || !hostdata->port_db[j].wwn) {
break; break;
} }
} }
if (j == QLOGICFC_MAX_ID + 1) if (j == QLOGICFC_MAX_ID + 1)
printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id); printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id);
if (!hostdata->port_db[j].wwn) { if (!hostdata->port_db[j].wwn) {
hostdata->port_db[j].loop_id = temp[i].loop_id; hostdata->port_db[j].loop_id = mapx->loop_id;
hostdata->port_db[j].wwn = temp[i].wwn; hostdata->port_db[j].wwn = mapx->wwn;
} }
} else } else
hostdata->port_db[i].loop_id = temp[i].loop_id; hostdata->port_db[i].loop_id = mapx->loop_id;
} }
isp2x00_enable_irqs(host); isp2x00_enable_irqs(host);
kfree(map);
fini:
return 0; return 0;
} }
......
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