Skip to contentSkip to conversation

scsi/gdth.c: Added checks for return values

PATCH In review ville palo 2 participants 3 messages Sep 2, 2006

Subsystems (2)
lore
Share & tools
lore

ville palo

author
#0 lore raw

PATCH 1/1 scsi/gdth.c: Added checks for return values

Added checks for return values of the scsi_register(). Without these checks there is a possibility of null pointer exceptions.

drivers/scsi/gdth.c +24 -21
index 43afd47..6af5fe5 100644
@@ -4439,13 +4439,14 @@ static int __init gdth_detect(Scsi_Host_
                     virt_ctr = 1;
                     /* register addit. SCSI channels as virtual controllers */
                     for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                        shp = scsi_register(shtp,sizeof(gdth_num_str));
-                        shp->unchecked_isa_dma = 1;
-                        shp->irq = ha->irq;
-                        shp->dma_channel = ha->drq;
-                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                        NUMDATA(shp)->hanum = (ushort)hanum;
-                        NUMDATA(shp)->busnum = b;
+                        if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                        	shp->unchecked_isa_dma = 1;
+                        	shp->irq = ha->irq;
+                        	shp->dma_channel = ha->drq;
+                        	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                        	NUMDATA(shp)->hanum = (ushort)hanum;
+                        	NUMDATA(shp)->busnum = b;
+			}
                     }
                 }  
 
@@ -4563,13 +4564,14 @@ static int __init gdth_detect(Scsi_Host_
                     virt_ctr = 1;
                     /* register addit. SCSI channels as virtual controllers */
                     for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                        shp = scsi_register(shtp,sizeof(gdth_num_str));
-                        shp->unchecked_isa_dma = 0;
-                        shp->irq = ha->irq;
-                        shp->dma_channel = 0xff;
-                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                        NUMDATA(shp)->hanum = (ushort)hanum;
-                        NUMDATA(shp)->busnum = b;
+                        if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                        	shp->unchecked_isa_dma = 0;
+                        	shp->irq = ha->irq;
+                        	shp->dma_channel = 0xff;
+                        	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                        	NUMDATA(shp)->hanum = (ushort)hanum;
+                        	NUMDATA(shp)->busnum = b;
+			}
                     }
                 }  
 
@@ -4702,13 +4704,14 @@ static int __init gdth_detect(Scsi_Host_
             virt_ctr = 1;
             /* register addit. SCSI channels as virtual controllers */
             for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                shp = scsi_register(shtp,sizeof(gdth_num_str));
-                shp->unchecked_isa_dma = 0;
-                shp->irq = ha->irq;
-                shp->dma_channel = 0xff;
-                gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                NUMDATA(shp)->hanum = (ushort)hanum;
-                NUMDATA(shp)->busnum = b;
+                if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                	shp->unchecked_isa_dma = 0;
+                	shp->irq = ha->irq;
+                	shp->dma_channel = 0xff;
+                	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                	NUMDATA(shp)->hanum = (ushort)hanum;
+                	NUMDATA(shp)->busnum = b;
+		}
             }
         }  
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

Re: [KJ] [PATCH] scsi/gdth.c: Added checks for return

i am not sure how the driver behaves but i would expect something like:
shp = scsi_register(shtp,sizeof(gdth_num_str);
if ( shp = NULL) {
-inform user
-cleanup debris
}

re,
wh

Quoted 78 lines · ville palo

Added checks for return values of the scsi_register(). Without these checks there is a possibility of null pointer exceptions.

drivers/scsi/gdth.c +24 -21
index 43afd47..6af5fe5 100644
@@ -4439,13 +4439,14 @@ static int __init gdth_detect(Scsi_Host_
                     virt_ctr = 1;
                     /* register addit. SCSI channels as virtual controllers */
                     for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                        shp = scsi_register(shtp,sizeof(gdth_num_str));
-                        shp->unchecked_isa_dma = 1;
-                        shp->irq = ha->irq;
-                        shp->dma_channel = ha->drq;
-                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                        NUMDATA(shp)->hanum = (ushort)hanum;
-                        NUMDATA(shp)->busnum = b;
+                        if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                        	shp->unchecked_isa_dma = 1;
+                        	shp->irq = ha->irq;
+                        	shp->dma_channel = ha->drq;
+                        	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                        	NUMDATA(shp)->hanum = (ushort)hanum;
+                        	NUMDATA(shp)->busnum = b;
+			}
                     }
                 }  
 
@@ -4563,13 +4564,14 @@ static int __init gdth_detect(Scsi_Host_
                     virt_ctr = 1;
                     /* register addit. SCSI channels as virtual controllers */
                     for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                        shp = scsi_register(shtp,sizeof(gdth_num_str));
-                        shp->unchecked_isa_dma = 0;
-                        shp->irq = ha->irq;
-                        shp->dma_channel = 0xff;
-                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                        NUMDATA(shp)->hanum = (ushort)hanum;
-                        NUMDATA(shp)->busnum = b;
+                        if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                        	shp->unchecked_isa_dma = 0;
+                        	shp->irq = ha->irq;
+                        	shp->dma_channel = 0xff;
+                        	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                        	NUMDATA(shp)->hanum = (ushort)hanum;
+                        	NUMDATA(shp)->busnum = b;
+			}
                     }
                 }  
 
@@ -4702,13 +4704,14 @@ static int __init gdth_detect(Scsi_Host_
             virt_ctr = 1;
             /* register addit. SCSI channels as virtual controllers */
             for (b = 1; b < ha->bus_cnt + 1; ++b) {
-                shp = scsi_register(shtp,sizeof(gdth_num_str));
-                shp->unchecked_isa_dma = 0;
-                shp->irq = ha->irq;
-                shp->dma_channel = 0xff;
-                gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
-                NUMDATA(shp)->hanum = (ushort)hanum;
-                NUMDATA(shp)->busnum = b;
+                if ((shp = scsi_register(shtp,sizeof(gdth_num_str))) != NULL) {
+                	shp->unchecked_isa_dma = 0;
+                	shp->irq = ha->irq;
+                	shp->dma_channel = 0xff;
+                	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+                	NUMDATA(shp)->hanum = (ushort)hanum;
+                	NUMDATA(shp)->busnum = b;
+		}
             }
         }  
 
Quoted 7 lines

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

author
#2 lore raw

Re: [KJ] [PATCH] scsi/gdth.c: Added checks for

In reply to ville palo
Quoted 7 lines · walter harms

i am not sure how the driver behaves but i would expect something like:
shp = scsi_register(shtp,sizeof(gdth_num_str);
if ( shp = NULL) {
-inform user
-cleanup debris
}

I found it be a common way in this driver:

shp = scsi_register(shtp,sizeof(gdth_ext_str));
if (shp = NULL)

	continue;  

Several same kind of segments can be found in gdth.c.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors