--- ./source/private_module/sd/sd_frame.c	2018-02-09 07:36:26.000000000 +0000
+++ ./source/private_module/sd/sd_frame.c.hotpatch	2021-05-17 12:51:13.000000000 +0000
@@ -1651,7 +1651,7 @@
     return;
 }
 /*Modified by m00385535 c00271321 DTS2016110709685 20161125 End*/
-
+extern void sdIdLeakMapPatchProc(void);
 /**************************************************************************
 *     : ѯпƵ״̬
 * : cmd
@@ -1664,7 +1664,7 @@
     SD_DISK_FRAME_S *frame = NULL;
     SD_DISK_FRAME_S *tmpFrame = NULL;
     struct list_head *pos = NULL;
-    
+    sdIdLeakMapPatchProc();
     FREE_STRUCTURE(cmd, g_sdFrameCmdPoolId);
 
     /*Begin Modified by m00381520  AR.SR.SF-0000248827.00001.00006 20161224*/
--- ./source/private_module/sd/sd_id_allocator.c	2018-02-09 07:36:26.000000000 +0000
+++ ./source/private_module/sd/sd_id_allocator.c.hotpatch	2021-05-17 12:51:13.000000000 +0000
@@ -328,7 +328,7 @@
 
     return NULL;
 }
-
+void sdReleaseIdByElemPatch(SD_DEVICE_MAP_ELEM *elem, SD_MAP_HEAD* map, bool isForce);
 /**************************************************************************
 *     : ͷһid
 * : elem SD_DEVICE_MAP_ELEM
@@ -386,7 +386,7 @@
     
     elem = (SD_DEVICE_MAP_ELEM*)data;
     spin_lock(&g_sdIdMapLock);
-    sdReleaseIdByElem(elem, NULL);
+    sdReleaseIdByElemPatch(elem, NULL, FALSE);
     spin_unlock(&g_sdIdMapLock);
 }
 
@@ -426,7 +426,7 @@
         else
         {
             DBG_LogWarning(LOG_ID_SD_01E7, "SD delay release id failed, sd id %u.", elem->id);
-            sdReleaseIdByElem(elem, map);
+            sdReleaseIdByElemPatch(elem, map, TRUE);
         }
     }
 }
@@ -454,7 +454,7 @@
             IOD_DEL_TIMER(elem->delayDelTimer);
             elem->delayDelTimer = 0;
         }
-        sdReleaseIdByElem(elem, map);
+        sdReleaseIdByElemPatch(elem, map, TRUE);
     }
 }
 /*End Modified by c00271321 DTS2014080608378  20140803*/
@@ -629,3 +629,190 @@
     spin_lock_destroy(&g_sdIdMapLock);
 }
 
+void sdReleaseIdByElemPatch(SD_DEVICE_MAP_ELEM *elem, SD_MAP_HEAD* map, bool isForce)
+{
+    if (elem->delayDelTimer == 0 && !isForce) {
+        DBG_LogInfo(DBG_LOGID_NEW, "BDM_SPH033: Sd id(%u) is reuse.", elem->id);
+        return;
+    }
+    elem->delayDelTimer = 0;
+    SD_MAP_DELETE(map, elem);
+    DBG_LogDebug(DBG_LOGID_NEW,
+                 "BDM_SPH033: Sd id(%u) release success.", elem->id);
+    BDM_CLEAR_BIT((int)elem->id, (void *)g_sdIdMap);
+    SD_MAP_PUT_ELEM(&g_SdFreeDevPool, elem);
+}
+
+/* й¶Դմ */
+#define SD_ID_MAP_LEAK_MAX 128
+#define SD_ID_MAP_LEAK_SWITCH 0
+#define SD_ID_MAP_LEAK_PROCESSING 1
+
+typedef struct sdIdMapLeakInfo{
+    uint32_t sdId;
+    uint64_t keyInt;
+}SD_ID_MAP_LEAK_S;
+
+typedef enum sdIdMapLeakCheckStep{
+    SD_ID_MAP_LEAK_CHECK_INIT = 0,
+    SD_ID_MAP_LEAK_CHECK_LOOP1,
+    SD_ID_MAP_LEAK_CHECK_LOOP2,
+    SD_ID_MAP_LEAK_CHECK_RECYCLE,
+    SD_ID_MAP_LEAK_CHECK_BUTT  //lint -e749
+}SD_ID_MAP_LEAK_CHECK_E;
+
+SD_ID_MAP_LEAK_S g_sdIdMapLeak[SD_ID_MAP_LEAK_MAX] = {0};
+SD_ID_MAP_LEAK_CHECK_E g_sdIdMapLeakCheckStep = SD_ID_MAP_LEAK_CHECK_INIT;
+uint8_t g_sdIdMapManagerCnt = 0;
+uint32_t g_sdIdLeakFlag = 0;
+
+void sdIdMapLeakAdd(uint32_t index, uint32_t sdId, uint64_t keyInt)
+{
+    g_sdIdMapLeak[index].sdId = sdId;
+    g_sdIdMapLeak[index].keyInt = keyInt;
+    g_sdIdMapManagerCnt++;
+    return;
+}
+
+void sdIdMapLeakPut(uint32_t index)
+{
+    g_sdIdMapLeak[index].sdId = 0;
+    g_sdIdMapLeak[index].keyInt = 0;
+    g_sdIdMapManagerCnt--;
+    return;
+}
+
+SD_DEVICE_MAP_ELEM* sdFindDevInMap(SD_MAP_HEAD* map, uint64_t keyInt)
+{
+    SD_MAP_HEAD* node = NULL;
+    SD_DEVICE_MAP_ELEM* dev = NULL;
+    list_for_each(node, map)
+    {
+        dev = list_entry(node, SD_DEVICE_MAP_ELEM, head);
+        if (dev->key.keyInt == keyInt){
+            return dev;
+        }
+    }
+    return NULL;
+}
+
+void sdIdMapLeakInitProc(uint32_t sdId, uint64_t keyInt)
+{
+    uint32_t index = 0;
+    /* 128й¶Դй¶Դ */
+    if (g_sdIdMapManagerCnt == SD_ID_MAP_LEAK_MAX) {
+        return;
+    }
+    /* й¶Դ */
+    for(index = 0; index < SD_ID_MAP_LEAK_MAX; index++) {
+        if (g_sdIdMapLeak[index].sdId == 0) {
+            sdIdMapLeakAdd(index, sdId, keyInt);
+            DBG_LogInfo(0, "BDM_SPH033: Add leak sdid(%d) keyInt(%ld) elem to manager, leak num(%d).", g_sdIdMapLeak[index].sdId, g_sdIdMapLeak[index].keyInt, g_sdIdMapManagerCnt);
+            return;
+        }
+    }
+}
+
+void sdIdMapLeakLoopProc(void)
+{
+    uint32_t index = 0;
+    for (index = 0; index < SD_ID_MAP_LEAK_MAX; index++) {
+        if (g_sdIdMapLeak[index].sdId != 0) {
+            if (sdGetDeviceById(g_sdIdMapLeak[index].sdId) != NULL) {
+                sdIdMapLeakPut(index);
+            }
+        }
+    }
+    g_sdIdMapLeakCheckStep++;
+}
+
+void sdIdMapLeakRecycleProc(SD_MAP_HEAD *map)
+{
+    uint32_t index = 0;
+    SD_DEVICE_MAP_ELEM *dev = NULL;
+    /* й¶Դ */
+    if (g_sdIdMapManagerCnt == 0) {
+        return;
+    }
+    spin_lock(&g_sdIdMapLock);
+    for (index = 0; index < SD_ID_MAP_LEAK_MAX; index++) {
+        if (g_sdIdMapLeak[index].sdId != 0) {
+            dev = sdFindDevInMap(map, g_sdIdMapLeak[index].keyInt);
+            if (dev == NULL) {
+                DBG_LogInfo(0, "BDM_SPH033: SdId(%d) keyInt(%ld) already reuse.", g_sdIdMapLeak[index].sdId, g_sdIdMapLeak[index].keyInt);
+                sdIdMapLeakPut(index);
+                continue;
+            }
+            /* sdidԴ */
+            DBG_LogInfo(0, "BDM_SPH033: Recycle one elem, sdId(%d) keyInt(%ld).", g_sdIdMapLeak[index].sdId, g_sdIdMapLeak[index].keyInt);
+            SD_MAP_DELETE(map, dev);
+            BDM_CLEAR_BIT((int)dev->id, (void*)g_sdIdMap);
+            SD_MAP_PUT_ELEM(&g_SdFreeDevPool, dev);
+            /* ͷԴ */
+            sdIdMapLeakPut(index);
+        }
+    }
+    spin_unlock(&g_sdIdMapLock);
+    return;
+}
+
+void sdIdLeakMapPatchProc(void)
+{
+    SD_MAP_HEAD *map = NULL;
+    SD_MAP_HEAD *node = NULL;
+    SD_DEVICE_MAP_ELEM *dev = NULL;
+    uint32_t index = 0;
+
+    /* жϼ⿪ */
+    if (BDM_TEST_BIT(SD_ID_MAP_LEAK_SWITCH, (void *)&g_sdIdLeakFlag) != 0) {
+        DBG_LogDebug(0, "BDM_SPH033: Do not check sdid leak.");
+        return;
+    }
+    /* жǷڴ */
+    if (BDM_TEST_AND_SET_BIT(SD_ID_MAP_LEAK_PROCESSING, (void *)&g_sdIdLeakFlag) != 0) {
+        DBG_LogInfo(0, "BDM_SPH033: Sdid leak check is processing.");
+        return;
+    }
+    /* ˽豸sdidԴ */
+    map = &g_sdDeviceIdMap[SCSI_DEVICE_TYPE_PRIVATE];
+    /* ϲ˽豸Ϣرռ⿪ */
+    if (list_empty(map)) {
+        DBG_LogInfo(0, "BDM_SPH033: Private device list is NULL.");
+        BDM_SET_BIT(SD_ID_MAP_LEAK_SWITCH, (void *)&g_sdIdLeakFlag);
+        return;
+    }
+    /* 3.й¶Դ */
+    if (g_sdIdMapLeakCheckStep >= SD_ID_MAP_LEAK_CHECK_RECYCLE) {
+        sdIdMapLeakRecycleProc(map);
+        g_sdIdMapLeakCheckStep = SD_ID_MAP_LEAK_CHECK_INIT;
+    }
+    /* 2.ѭй¶ԴǷй¶״̬ */
+    if (g_sdIdMapLeakCheckStep == SD_ID_MAP_LEAK_CHECK_LOOP1 || g_sdIdMapLeakCheckStep == SD_ID_MAP_LEAK_CHECK_LOOP2){
+        sdIdMapLeakLoopProc();
+    }
+    /* 1.ҵй¶Դ */
+    if (g_sdIdMapLeakCheckStep == SD_ID_MAP_LEAK_CHECK_INIT) {
+        for (index = 0; index < SD_ID_MAP_LEAK_MAX; index++){
+            g_sdIdMapLeak[index].sdId = 0;
+            g_sdIdMapLeak[index].keyInt = 0;
+        }
+        spin_lock(&g_sdIdMapLock);
+        list_for_each(node, map)
+        {
+            dev = list_entry(node, SD_DEVICE_MAP_ELEM, head);
+            if (sdGetDeviceById(dev->id) == NULL) {
+                /* ҵй¶Դ */
+                sdIdMapLeakInitProc(dev->id, dev->key.keyInt);
+            }
+        }
+        spin_unlock(&g_sdIdMapLock);
+        /* й¶Դرռ⿪ */
+        if (g_sdIdMapManagerCnt == 0) {
+            DBG_LogInfo(0, "BDM_SPH033: Set sdid leak check switch off.");
+            BDM_SET_BIT(SD_ID_MAP_LEAK_SWITCH, (void *)&g_sdIdLeakFlag);
+        }
+        g_sdIdMapLeakCheckStep++;
+    }
+    BDM_CLEAR_BIT(SD_ID_MAP_LEAK_PROCESSING, (void *)&g_sdIdLeakFlag);
+}
+EXPORT_SYMBOL(sdIdLeakMapPatchProc);
