Skip to contentSkip to conversation

Fix in eeprom.c

DISCUSSION Jean Delvare 4 participants 11 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

what do you think about this fix?

You're correct. Nice catching. I've applied it to our CVS repository.

Will you send a patch to Greg KH for the eeprom driver in Linux 2.6, or do you want me to do so?

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#1 lore raw
Quoted 8 lines

I have seen another problem regarding (MIPS) architecture:

	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct eeprom_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}
Quoted 7 lines

you request memory for two structures at a time.
The problem is, that the eeprom_data structure is not aligned on an 8 byte boundary, which catches an
unaligned kernel exception when working on the update_lock semaphore on our machine (www.cantastic.de)
I would propose that you use two kmalloc() (kfree) for each individual structure, which solves our problem.

This is quite a problem you reveal there. It happens that all our chip drivers in both CVS and Linux 2.6 use this single memory allocation method. This suggests that no i2c chip driver (at least coming from the lm_sensors project) would work on any architecture not supporting non-aligned memory accesses.

I'm a bit surprised that this would have been uncovered until today. Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#2 lore raw
In reply to Jean Delvare
Quoted 3 lines · Jean Delvare

Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Yeah, we probably should :(

thanks,

greg k-h

#3 lore raw
In reply to Jean Delvare

agreed

Quoted 14 lines · Greg KH
Quoted 3 lines · Jean Delvare

Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Yeah, we probably should :(

thanks,

greg k-h

#4 lore raw
In reply to Jean Delvare

Hi Jean,

currently I'm only working with Linux MIPS 2.4 kernel, so it would be nice if you could forward the patch for 2.6.

I have seen another problem regarding (MIPS) architecture:

	if (!(new_client = kmalloc(sizeof(struct i2c_client) +
				   sizeof(struct eeprom_data),
				   GFP_KERNEL))) {
		err = -ENOMEM;
		goto ERROR0;
	}

you request memory for two structures at a time.
The problem is, that the eeprom_data structure is not aligned on an 8 byte boundary, which catches an
unaligned kernel exception when working on the update_lock semaphore on our machine (www.cantastic.de)
I would propose that you use two kmalloc() (kfree) for each individual structure, which solves our problem.

regards
Ralf

Quoted 6 lines
Quoted 1 line

what do you think about this fix?

You're correct. Nice catching. I've applied it to our CVS repository.

Will you send a patch to Greg KH for the eeprom driver in Linux 2.6, or do you want me to do so?

#5 lore raw
In reply to Jean Delvare
Quoted 5 lines
Quoted 3 lines

Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Yeah, we probably should :(

OK... Here we go. I've converted all drivers in our CVS repository to a new model where we do the two kmallocs separately. I didn't commit it yet because it's a very important change (47 chip drivers affected). So I'd appreciate code reviews and tests before I apply it.

The patch is here:
http://jdelvare.net1.nerim.net/sensors/lm_sensors-CVS-separate-mallocs.diff
It applies on latest CVS.

I tested only the eeprom and lm90 drivers so far. Seems to work, but the changes are error-prone so what it "seems" is hardly enough to be sure it's correct.

Ralf, can you confirm that the patche solves your memory alignment problem with the eeprom driver on MIPS?

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#6 lore raw
In reply to Jean Delvare
Quoted 11 lines · Jean Delvare
Quoted 5 lines
Quoted 3 lines

Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Yeah, we probably should :(

OK... Here we go. I've converted all drivers in our CVS repository to a new model where we do the two kmallocs separately. I didn't commit it yet because it's a very important change (47 chip drivers affected). So I'd appreciate code reviews and tests before I apply it.

Quoted 7 lines

The patch is here:
http://jdelvare.net1.nerim.net/sensors/lm_sensors-CVS-separate-mallocs.diff
It applies on latest CVS.

I tested only the eeprom and lm90 drivers so far. Seems to work, but the changes are error-prone so what it "seems" is hardly enough to be sure it's correct.

At a quick glance it looks sane.

thanks,

greg k-h

#7 lore raw
In reply to Jean Delvare
Quoted 10 lines
Quoted 10 lines

OK... Here we go. I've converted all drivers in our CVS repository to a new model where we do the two kmallocs separately. I didn't commit it yet because it's a very important change (47 chip drivers affected). So I'd appreciate code reviews and tests before I apply it.

The patch is here:
http://jdelvare.net1.nerim.net/sensors/lm_sensors-CVS-separate-mallocs.diff
It applies on latest CVS.

Quoted 5 lines
Quoted 3 lines

I tested only the eeprom and lm90 drivers so far. Seems to work, but the changes are error-prone so what it "seems" is hardly enough to be sure it's correct.

At a quick glance it looks sane.

Well, I doubt that a quick glance is enough to ensure that the patch didn't break anything. I'm confident that the memory allocation and "normal" freeing are correct. What I consider error-prone is the error handling in detect functions. In several cases I had to rename labels. It's hard to be sure that all error paths are absolutely correct, although I did my best not to screw anything up.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#8 lore raw
In reply to Jean Delvare

Jean,
I have applied your eeprom.c patch and tested. Your fix is quite similar to mine and works fine for me.

Thanks
--
Ralf

Quoted 15 lines

-----Ursprungliche Nachricht-----
Von: ralf@arbeitsgruppe [mailto:ralf@arbeitsgruppe]Im Auftrag von Jean Delvare
Gesendet: Donnerstag, 1. April 2004 23:17
An: LM Sensors
Cc: Ralf Roesch; Greg KH
Betreff: Re: Fix in eeprom.c

Quoted 5 lines
Quoted 3 lines

Greg, I would be interested in your opinion. Should we update all our chip drivers to have two memory allocations instead of a single one for this?

Yeah, we probably should :(

Quoted 7 lines

OK... Here we go. I've converted all drivers in our CVS repository to a new model where we do the two kmallocs separately. I didn't commit it yet because it's a very important change (47 chip drivers affected). So I'd appreciate code reviews and tests before I apply it.

The patch is here:
http://jdelvare.net1.nerim.net/sensors/lm_sensors-CVS-separate-mal

locs.diff
It applies on latest CVS.

I tested only the eeprom and lm90 drivers so far. Seems to work, but the changes are error-prone so what it "seems" is hardly enough to be sure it's correct.

Ralf, can you confirm that the patche solves your memory alignment problem with the eeprom driver on MIPS?

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#9 lore raw
In reply to Jean Delvare

Hi Ralf,

Quoted 2 lines

I have applied your eeprom.c patch and tested. Your fix is quite similar to mine and works fine for me.

A different fix was prefered, causing less changes in the drivers (so less error-prone). I just commited the change to our CVS repository. I would appreciate it if you could check it out and test.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#10 lore raw
In reply to Jean Delvare

Hi Jean,

sorry for the long delay. I have tested the new source. It seems to be o.k. so far for our system. Thanks and regards
Ralf

Quoted 25 lines

-----Ursprungliche Nachricht-----
Von: ralf@arbeitsgruppe [mailto:ralf@arbeitsgruppe]Im Auftrag von Jean Delvare
Gesendet: Samstag, 17. April 2004 19:22
An: Ralf Roesch
Cc: [email protected]
Betreff: Re: Fix in eeprom.c

Hi Ralf,

Quoted 2 lines

I have applied your eeprom.c patch and tested. Your fix is quite similar to mine and works fine for me.

A different fix was prefered, causing less changes in the drivers (so less error-prone). I just commited the change to our CVS repository. I would appreciate it if you could check it out and test.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/