drivers/scsi: Check NULL for kmalloc() return
Subsystems (2)
PATCH 1/1 drivers/scsi: Check NULL for kmalloc() return
Verify that ch->dt is not NULL before using it:
ch-dt[elem] = value;
--- drivers/scsi/ch.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/scsi/ch.c +4 -0
@@ -353,6 +353,10 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) +return -ENOMEM ; +for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { id =-1 ; lun =0 ;
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;
It looks like buffer should be freed as well?
julia
Quoted 26 lines
Signed-off-by Davidlohr Bueso--- drivers/scsi/ch.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)drivers/scsi/ch.c +4
-1@@ -353,6 +353,10 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) +return -ENOMEM ; +for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { id =-1 ; lun =0 ; --To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;It looks like buffer should be freed as well?
The way I see it, this is done in ch_remove()
Davidlohr
Quoted 33 lines
julia
Quoted 22 lines
Signed-off-by Davidlohr Bueso--- drivers/scsi/ch.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)drivers/scsi/ch.c +4
-1@@ -353,6 +353,10 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) +return -ENOMEM ; +for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { id =-1 ; lun =0 ; --Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Davidlohr Bueso A.
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;It looks like buffer should be freed as well?
The way I see it, this is done in
ch_remove()
I don't see that at all. buffer appears to be a variable that is local to ch_readconfig and is passed down to other functions, but never saved anywhere. Furthermore buffer is freed in the normal exit of the function, so it seems likely that it should be freed on an early exit as well.
julia
Quoted 8 lines · Julia Lawall
Quoted 6 lines · Davidlohr Bueso A.
Quoted 5 lines · Julia Lawall
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
It looks like buffer should be freed as well?
The way I see it, this is done in
ch_remove()I don't see that at all. buffer appears to be a variable that is local to
ch_readconfigand is passed down to other functions, but never saved anywhere. Furthermore buffer is freed in the normal exit of the function, so it seems likely that it should be freed on an early exit as well.
Sorry, misread, for some reason I thought you were talking about freeing ch->dt, correting patch.
Thanks,
Davidlohr
--- drivers/scsi/ch.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/scsi/ch.c +6 -0
@@ -353,6 +353,12 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) { +free (buffer); +return -ENOMEM ; + } +for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { id =-1 ; lun =0 ;
Quoted 34 lines · Davidlohr Bueso A.
Quoted 8 lines · Julia Lawall
Quoted 6 lines · Davidlohr Bueso A.
Quoted 5 lines · Julia Lawall
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;Quoted 8 lines
Quoted 3 lines
Quoted 1 line
It looks like buffer should be freed as well?
The way I see it, this is done in
ch_remove()I don't see that at all. buffer appears to be a variable that is local to
ch_readconfigand is passed down to other functions, but never saved anywhere. Furthermore buffer is freed in the normal exit of the function, so it seems likely that it should be freed on an early exit as well.Sorry, misread, for some reason I thought you were talking about freeing
ch->dt, correting patch.Thanks,
DavidlohrSigned-off-by Davidlohr Bueso <[email protected]>---
drivers/scsi/ch.c | 6 ++++++1 files changed, 6 insertions(+), 0 deletions(-)drivers/scsi/ch.c +0
-0
drivers/scsi/ch.c ch_readconfig(scsi_changer *ch) · line 358
Quoted 6 lines
drivers/scsi/ch.c +3
-0@@ -353,6 +353,12 @@ ch_readconfig(scsi_changer *ch) /* look up the devices of the data transfer elements */ ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device), GFP_KERNEL); + + if (!ch->dt) { + free(buffer);
kfree(buffer) ?
Quoted 7 lines
drivers/scsi/ch.c +3
-0+ return -ENOMEM; + } + for (elem = 0; elem < ch->counts[CHET_DT]; elem++) { id = -1; lun = 0;
Quoted 30 lines · Hannes Eder
Quoted 29 lines · Davidlohr Bueso A.
Quoted 8 lines · Julia Lawall
Quoted 6 lines · Davidlohr Bueso A.
Quoted 5 lines · Julia Lawall
Quoted 2 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;Quoted 8 lines
Quoted 3 lines
Quoted 1 line
It looks like buffer should be freed as well?
The way I see it, this is done in
ch_remove()I don't see that at all. buffer appears to be a variable that is local to
ch_readconfigand is passed down to other functions, but never saved anywhere. Furthermore buffer is freed in the normal exit of the function, so it seems likely that it should be freed on an early exit as well.Sorry, misread, for some reason I thought you were talking about freeing
ch->dt, correting patch.Thanks,
DavidlohrSigned-off-by Davidlohr Bueso <[email protected]>---
drivers/scsi/ch.c | 6 ++++++1 files changed, 6 insertions(+), 0 deletions(-)
Quoted 13 lines
drivers/scsi/ch.c ch_readconfig(scsi_changer *ch) · line 358
Quoted 11 lines
drivers/scsi/ch.c +3
-0@@ -353,6 +353,12 @@ ch_readconfig(scsi_changer *ch) /* look up the devices of the data transfer elements */ ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device), GFP_KERNEL); + + if (!ch->dt) { + free(buffer);kfree(buffer) ?
Wow, unbelievable, that'll teach me!
--- drivers/scsi/ch.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/scsi/ch.c +6 -0
@@ -353,6 +353,12 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) { +kfree (buffer); +return -ENOMEM ; + } +for (elem =0 ; elem < ch->counts[CHET_DT ]; elem++) { id =-1 ; lun =0 ;
James Bottomley
maintainerQuoted 4 lines · Davidlohr Bueso A.
Verify that
ch->dtis not NULL before using it:
ch-dt[elem] = value;Signed-off-by Davidlohr Bueso
This actually needs to be an email address, not just a name, so
Quoted 9 lines
--- drivers/scsi/ch.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)drivers/scsi/ch.c +0
-0
drivers/scsi/ch.c ch_readconfig(scsi_changer *ch) · line 358
Quoted 6 lines
drivers/scsi/ch.c +3
-0@@ -353,6 +353,10 @@ ch_readconfig(scsi_changer *ch)/* look up the devices of the data transfer elements */ ch->dt =kmalloc (ch->counts[CHET_DT ]*sizeof (struct scsi_device ),GFP_KERNEL ); + +if (!ch->dt) +return -ENOMEM ;
This isn't quite right because you'll leak the memory allocated for buffer here.
For bonus points, the GFP_DMA in the kzalloc() of buffer is bogus ... this routine can sleep at all points.
James