Skip to contentSkip to conversation

Would the father of init_mem_lth please stand up

DISCUSSION Pete Zaitcev 4 participants 7 messages Dec 8, 2001

lore
Share & tools
lore
#0 lore raw

Really someone needs slapping across. What kind of code is that (in 2.5.1-pre6):

drivers/scsi/sd.c:sd_init()

        /* allocate memory */

#define init_mem_lth(x,n) x = kmalloc((n) * sizeof(*x), GFP_ATOMIC)
#define zero_mem_lth(x,n) memset(x, 0, (n) * sizeof(*x))

        init_mem_lth(rscsi_disks, sd_template.dev_max);
        init_mem_lth(sd_sizes, maxparts);
        init_mem_lth(sd_blocksizes, maxparts);
        init_mem_lth(sd, maxparts);
        init_mem_lth(sd_gendisks, N_USED_SD_MAJORS);
        init_mem_lth(sd_max_sectors, sd_template.dev_max << 4);

        if (!rscsi_disks || !sd_sizes || !sd_blocksizes || !sd || !sd_gendisks)
                goto cleanup_mem;

#undef init_mem_lth
#undef zero_mem_lth
.....................
cleanup_mem:

        kfree(sd_gendisks);
        kfree(sd);
        kfree(sd_blocksizes);
        kfree(sd_sizes);
        kfree(rscsi_disks);

However, it's not only about the puking and keyboard cleanups. The code is buggy as well. Scenario:

0. User inserts a large number of FC-AL adapters with 56 disks each
1. modprobe sd_mod
No SCSI hosts, sd_init() is NOT called.
2. modprobe qla_something
sd_init is called and fails on sd_gendisks. modprobe fails. sd_sizes, sd_blocksizes, etc. are LEFT DANGLING
3. modprobe qla_something
sd_init is called and fails on sd_sizes.
kfree is called with a bunch of dangling pointers

I stringly urge Linus to drop this so-called "cleanup" from 2.5.1.

No doubt, the existing code was bad. I fixed it somewhat for 2.4, and am feeding it to Marcelo. I can forward-port that to 2.5 if anyone is interested.

-- Pete

#1 lore raw
Quoted 2 lines · Pete Zaitcev

Really someone needs slapping across. What kind of code is that (in 2.5.1-pre6):

It went in with the bio stuff, without being too much of a finger-pointer I think it is Andries.

Quoted 3 lines

No doubt, the existing code was bad. I fixed it somewhat for 2.4, and am feeding it to Marcelo. I can forward-port that to 2.5 if anyone is interested.

Please, just fix it in 2.5 too.

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Pete Zaitcev
Quoted 2 lines

Really someone needs slapping across. What kind of code is that (in 2.5.1-pre6):

Whoever merged that crap also wants a good kicking. First we have the joke ps/2 merge, now this. Is Linus trying to force someone to take over or is small children combined with a pending christmas really the doom that some folks claim 8)

Quoted 5 lines

I stringly urge Linus to drop this so-called "cleanup" from 2.5.1.

No doubt, the existing code was bad. I fixed it somewhat for 2.4, and am feeding it to Marcelo. I can forward-port that to 2.5 if anyone is interested.

Did you clean it up as far as making the disks an array of pointers not of objects ?

Alan

#3 lore raw
In reply to Pete Zaitcev
Quoted 29 lines · Pete Zaitcev

drivers/scsi/sd.c:sd_init()

        /* allocate memory */

#define init_mem_lth(x,n) x = kmalloc((n) * sizeof(*x), GFP_ATOMIC)
#define zero_mem_lth(x,n) memset(x, 0, (n) * sizeof(*x))

        init_mem_lth(rscsi_disks, sd_template.dev_max);
        init_mem_lth(sd_sizes, maxparts);
        init_mem_lth(sd_blocksizes, maxparts);
        init_mem_lth(sd, maxparts);
        init_mem_lth(sd_gendisks, N_USED_SD_MAJORS);
        init_mem_lth(sd_max_sectors, sd_template.dev_max << 4);

        if (!rscsi_disks || !sd_sizes || !sd_blocksizes || !sd || !sd_gendisks)
                goto cleanup_mem;

#undef init_mem_lth
#undef zero_mem_lth
.....................
cleanup_mem:

        kfree(sd_gendisks);
        kfree(sd);
        kfree(sd_blocksizes);
        kfree(sd_sizes);
        kfree(rscsi_disks);

However, it's not only about the puking and keyboard cleanups. The code is buggy as well. Scenario:

Quoted 9 lines

0. User inserts a large number of FC-AL adapters with 56 disks each
1. modprobe sd_mod
No SCSI hosts, sd_init() is NOT called.
2. modprobe qla_something
sd_init is called and fails on sd_gendisks. modprobe fails. sd_sizes, sd_blocksizes, etc. are LEFT DANGLING
3. modprobe qla_something
sd_init is called and fails on sd_sizes.
kfree is called with a bunch of dangling pointers

I agree it's ugly, but why would kfree be called on dangling pointers? All those pointers are initialized again on every sd_init() call. And there are no "goto cleanup_mem"s between the kmallocs.

Eric

#4 lore raw
In reply to Pete Zaitcev
Quoted 5 lines · Eric Lammerts

I agree it's ugly, but why would kfree be called on dangling pointers? All those pointers are initialized again on every sd_init() call. And there are no "goto cleanup_mem"s between the kmallocs.

Eric

I was too rush - indeed there are no gotos between kmallocs. So the scenario that I presented cannot happen.

-- Pete

#5 lore raw
In reply to Pete Zaitcev
Quoted 8 lines
Quoted 3 lines

No doubt, the existing code was bad. I fixed it somewhat for 2.4, and am feeding it to Marcelo. I can forward-port that to 2.5 if anyone is interested.

Did you clean it up as far as making the disks an array of pointers not of objects ?

Alan

I was going to do it, but have not done yet.

BTW, it was pointed out that my analyzis of the init_mem_lth was completely wrong - there is no bug that I thought is there. So I better be careful with 2.4 changes.

-- Pete

#6 lore raw
Quoted 3 lines

BTW, it was pointed out that my analyzis of the init_mem_lth was completely wrong - there is no bug that I thought is there. So I better be careful with 2.4 changes.

Its merely hideously ugly and without taste. I didn't think there was anything else wrong with it 8)