From: Arjan van de Ven Hi, patches below are from me and Dave Jones to reduce stack usage some. * ide-cd: a few 512 byte scratch buffers can be static; they are just for putting "padding" sectors in that aren't used. * isdn: dynamic allocate big structures * sk98lin: dynamic allocate big structures * aic7xxx_old: constant array of PCI ID's can be static since it's read only --- 25-akpm/drivers/net/sk98lin/skgepnmi.c | 171 +++++++++++++++++++-------------- 1 files changed, 101 insertions(+), 70 deletions(-) diff -puN drivers/net/sk98lin/skgepnmi.c~stack-reductions-sk98lin drivers/net/sk98lin/skgepnmi.c --- 25/drivers/net/sk98lin/skgepnmi.c~stack-reductions-sk98lin Thu Mar 25 14:42:29 2004 +++ 25-akpm/drivers/net/sk98lin/skgepnmi.c Thu Mar 25 14:42:29 2004 @@ -3022,10 +3022,10 @@ unsigned int TableIndex, /* Index to the SK_U32 NetIndex) /* NetIndex (0..n), in single net mode always zero */ { SK_VPD_STATUS *pVpdStatus; + char *Buf; + char *KeyArr; + char *KeyStr; unsigned int BufLen; - char Buf[256]; - char KeyArr[SK_PNMI_VPD_ENTRIES][SK_PNMI_VPD_KEY_SIZE]; - char KeyStr[SK_PNMI_VPD_KEY_SIZE]; unsigned int KeyNo; unsigned int Offset; unsigned int Index; @@ -3035,13 +3035,30 @@ SK_U32 NetIndex) /* NetIndex (0..n), in int Ret; SK_U32 Val32; + Buf = kmalloc(256, GFP_KERNEL); + if (!Buf) + return -ENOMEM; + + KeyStr = kmalloc(SK_PNMI_VPD_KEY_SIZE, GFP_KERNEL); + if (!KeyStr) { + kfree(Buf); + return -ENOMEM; + } + + KeyArr = kmalloc (SK_PNMI_VPD_ENTRIES *SK_PNMI_VPD_KEY_SIZE, GFP_KERNEL); + if (!KeyArr) { + kfree(KeyStr); + kfree(Buf); + return -ENOMEM; + } + /* * Get array of all currently stored VPD keys */ - Ret = GetVpdKeyArr(pAC, IoC, &KeyArr[0][0], sizeof(KeyArr), &KeyNo); + Ret = GetVpdKeyArr(pAC, IoC, KeyArr, SK_PNMI_VPD_ENTRIES *SK_PNMI_VPD_KEY_SIZE, &KeyNo); if (Ret != SK_PNMI_ERR_OK) { *pLen = 0; - return (Ret); + goto ret; } /* @@ -3062,23 +3079,22 @@ SK_U32 NetIndex) /* NetIndex (0..n), in KeyStr[4] = 0; for (Index = 0; Index < KeyNo; Index ++) { - - if (SK_STRCMP(KeyStr, KeyArr[Index]) == 0) { + if (SK_STRCMP(KeyStr, KeyArr+Index) == 0) { FirstIndex = Index; LastIndex = Index+1; break; } } if (Index == KeyNo) { - *pLen = 0; - return (SK_PNMI_ERR_UNKNOWN_INST); + Ret = SK_PNMI_ERR_UNKNOWN_INST; + goto ret; } } else if (Instance != 1) { - *pLen = 0; - return (SK_PNMI_ERR_UNKNOWN_INST); + Ret = SK_PNMI_ERR_UNKNOWN_INST; + goto ret; } } @@ -3092,9 +3108,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in case OID_SKGE_VPD_FREE_BYTES: /* Check length of buffer */ if (*pLen < sizeof(SK_U32)) { - *pLen = sizeof(SK_U32); - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } /* Get number of free bytes */ pVpdStatus = VpdStat(pAC, IoC); @@ -3104,7 +3120,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR017MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } if ((pVpdStatus->vpd_status & VPD_VALID) == 0) { @@ -3112,7 +3129,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR018MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } Val32 = (SK_U32)pVpdStatus->vpd_free_rw; @@ -3122,22 +3140,20 @@ SK_U32 NetIndex) /* NetIndex (0..n), in case OID_SKGE_VPD_ENTRIES_LIST: /* Check length */ - for (Len = 0, Index = 0; Index < KeyNo; Index ++) { + for (Len = 0, Index = 0; Index < KeyNo; Index ++) + Len += SK_STRLEN(KeyArr+Index) + 1; - Len += SK_STRLEN(KeyArr[Index]) + 1; - } if (*pLen < Len) { - *pLen = Len; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } /* Get value */ *(pBuf) = (char)Len - 1; for (Offset = 1, Index = 0; Index < KeyNo; Index ++) { - - Len = SK_STRLEN(KeyArr[Index]); - SK_MEMCPY(pBuf + Offset, KeyArr[Index], Len); + Len = SK_STRLEN(KeyArr+Index); + SK_MEMCPY(pBuf + Offset, KeyArr+Index, Len); Offset += Len; @@ -3153,9 +3169,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in case OID_SKGE_VPD_ENTRIES_NUMBER: /* Check length */ if (*pLen < sizeof(SK_U32)) { - *pLen = sizeof(SK_U32); - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; } Val32 = (SK_U32)KeyNo; @@ -3168,12 +3183,13 @@ SK_U32 NetIndex) /* NetIndex (0..n), in for (Len = 0, Index = FirstIndex; Index < LastIndex; Index ++) { - Len += SK_STRLEN(KeyArr[Index]) + 1; + Len += SK_STRLEN(KeyArr+Index) + 1; } if (*pLen < Len) { *pLen = Len; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } /* @@ -3183,10 +3199,10 @@ SK_U32 NetIndex) /* NetIndex (0..n), in for (Offset = 0, Index = FirstIndex; Index < LastIndex; Index ++) { - Len = SK_STRLEN(KeyArr[Index]); + Len = SK_STRLEN(KeyArr+Index); *(pBuf + Offset) = (char)Len; - SK_MEMCPY(pBuf + Offset + 1, KeyArr[Index], + SK_MEMCPY(pBuf + Offset + 1, KeyArr+Index, Len); Offset += Len + 1; } @@ -3199,7 +3215,7 @@ SK_U32 NetIndex) /* NetIndex (0..n), in Index < LastIndex; Index ++) { BufLen = 256; - if (VpdRead(pAC, IoC, KeyArr[Index], Buf, + if (VpdRead(pAC, IoC, KeyArr+Index, Buf, (int *)&BufLen) > 0 || BufLen >= SK_PNMI_VPD_DATALEN) { @@ -3207,14 +3223,16 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR021, SK_PNMI_ERR021MSG); - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } Offset += BufLen + 1; } if (*pLen < Offset) { *pLen = Offset; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } /* @@ -3225,7 +3243,7 @@ SK_U32 NetIndex) /* NetIndex (0..n), in Index < LastIndex; Index ++) { BufLen = 256; - if (VpdRead(pAC, IoC, KeyArr[Index], Buf, + if (VpdRead(pAC, IoC, KeyArr+Index, Buf, (int *)&BufLen) > 0 || BufLen >= SK_PNMI_VPD_DATALEN) { @@ -3234,7 +3252,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR022MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } *(pBuf + Offset) = (char)BufLen; @@ -3246,15 +3266,15 @@ SK_U32 NetIndex) /* NetIndex (0..n), in case OID_SKGE_VPD_ACCESS: if (*pLen < LastIndex - FirstIndex) { - *pLen = LastIndex - FirstIndex; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } for (Offset = 0, Index = FirstIndex; Index < LastIndex; Index ++) { - if (VpdMayWrite(KeyArr[Index])) { + if (VpdMayWrite(KeyArr+Index)) { *(pBuf + Offset) = SK_PNMI_VPD_RW; } @@ -3269,9 +3289,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in case OID_SKGE_VPD_ACTION: Offset = LastIndex - FirstIndex; if (*pLen < Offset) { - *pLen = Offset; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } SK_MEMSET(pBuf, 0, Offset); *pLen = Offset; @@ -3280,9 +3300,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in default: SK_ERR_LOG(pAC, SK_ERRCL_SW, SK_PNMI_ERR023, SK_PNMI_ERR023MSG); - *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } } else { @@ -3297,14 +3317,16 @@ SK_U32 NetIndex) /* NetIndex (0..n), in Id == OID_SKGE_VPD_ACCESS) { *pLen = 0; - return (SK_PNMI_ERR_READ_ONLY); + Ret = SK_PNMI_ERR_READ_ONLY; + goto ret; } SK_ERR_LOG(pAC, SK_ERRCL_SW, SK_PNMI_ERR024, SK_PNMI_ERR024MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } /* @@ -3312,9 +3334,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in * length. It should at least have the size of one byte. */ if (*pLen < 1) { - *pLen = 1; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } /* @@ -3333,9 +3355,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in * an existing one. Check first the buffer length. */ if (*pLen < 4) { - *pLen = 4; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } KeyStr[0] = pBuf[1]; KeyStr[1] = pBuf[2]; @@ -3346,9 +3368,9 @@ SK_U32 NetIndex) /* NetIndex (0..n), in * read-only area? */ if (!VpdMayWrite(KeyStr)) { - *pLen = 0; - return (SK_PNMI_ERR_BAD_VALUE); + Ret = SK_PNMI_ERR_BAD_VALUE; + goto ret; } Offset = (int)pBuf[3] & 0xFF; @@ -3358,8 +3380,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in /* A preset ends here */ if (Action == SK_PNMI_PRESET) { - - return (SK_PNMI_ERR_OK); + Ret = SK_PNMI_ERR_OK; + goto ret; } /* Write the new entry or modify an existing one */ @@ -3367,7 +3389,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in if (Ret == SK_PNMI_VPD_NOWRITE ) { *pLen = 0; - return (SK_PNMI_ERR_BAD_VALUE); + Ret = SK_PNMI_ERR_BAD_VALUE; + goto ret; } else if (Ret != SK_PNMI_VPD_OK) { @@ -3375,7 +3398,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR025MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } /* @@ -3389,21 +3413,22 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR026MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } break; case SK_PNMI_VPD_DELETE: /* Check if the buffer size is plausible */ if (*pLen < 3) { - *pLen = 3; - return (SK_PNMI_ERR_TOO_SHORT); + Ret = SK_PNMI_ERR_TOO_SHORT; + goto ret; } if (*pLen > 3) { - *pLen = 0; - return (SK_PNMI_ERR_BAD_VALUE); + Ret = SK_PNMI_ERR_BAD_VALUE; + goto ret; } KeyStr[0] = pBuf[1]; KeyStr[1] = pBuf[2]; @@ -3411,25 +3436,22 @@ SK_U32 NetIndex) /* NetIndex (0..n), in /* Find the passed key in the array */ for (Index = 0; Index < KeyNo; Index ++) { - - if (SK_STRCMP(KeyStr, KeyArr[Index]) == 0) { - + if (SK_STRCMP(KeyStr, KeyArr+Index) == 0) break; - } } /* * If we cannot find the key it is wrong, so we * return an appropriate error value. */ if (Index == KeyNo) { - *pLen = 0; - return (SK_PNMI_ERR_BAD_VALUE); + Ret = SK_PNMI_ERR_BAD_VALUE; + goto ret; } if (Action == SK_PNMI_PRESET) { - - return (SK_PNMI_ERR_OK); + Ret =SK_PNMI_ERR_OK; + goto ret; } /* Ok, you wanted it and you will get it */ @@ -3440,7 +3462,8 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR027MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } /* @@ -3454,17 +3477,25 @@ SK_U32 NetIndex) /* NetIndex (0..n), in SK_PNMI_ERR028MSG); *pLen = 0; - return (SK_PNMI_ERR_GENERAL); + Ret = SK_PNMI_ERR_GENERAL; + goto ret; } break; default: *pLen = 0; - return (SK_PNMI_ERR_BAD_VALUE); + Ret = SK_PNMI_ERR_BAD_VALUE; + goto ret; } } - return (SK_PNMI_ERR_OK); + Ret = SK_PNMI_ERR_OK; + +ret: + kfree(KeyArr); + kfree(KeyStr); + kfree(Buf); + return Ret; } /***************************************************************************** _