|
| 1 | +From e317fa8a47a3718d21edc9b66a7126b021b8ee6e Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +From: Don Bollinger < [email protected]> |
| 4 | + |
| 5 | +Subject: [PATCH] Correct a panic inducing defect which is triggered on a read |
| 6 | + (or write) which begins beyond byte 128, on a byte which is not aligned on a |
| 7 | + 128 byte chunk boundary, and which crosses a chunk boundary. |
| 8 | +--- |
| 9 | + drivers/misc/eeprom/optoe.c | 27 ++++++++++++++------------- |
| 10 | + 1 file changed, 14 insertions(+), 13 deletions(-) |
| 11 | + |
| 12 | +diff --git a/drivers/misc/eeprom/optoe.c b/drivers/misc/eeprom/optoe.c |
| 13 | +index 7425bf6..1b64506 100644 |
| 14 | +--- a/drivers/misc/eeprom/optoe.c |
| 15 | ++++ b/drivers/misc/eeprom/optoe.c |
| 16 | +@@ -641,6 +641,7 @@ static ssize_t optoe_read_write(struct optoe_data *optoe, |
| 17 | + ssize_t retval; |
| 18 | + size_t pending_len = 0, chunk_len = 0; |
| 19 | + loff_t chunk_offset = 0, chunk_start_offset = 0; |
| 20 | ++ loff_t chunk_end_offset = 0; |
| 21 | + |
| 22 | + dev_dbg(&client->dev, |
| 23 | + "%s: off %lld len:%ld, opcode:%s\n", |
| 24 | +@@ -678,30 +679,30 @@ static ssize_t optoe_read_write(struct optoe_data *optoe, |
| 25 | + /* |
| 26 | + * Compute the offset and number of bytes to be read/write |
| 27 | + * |
| 28 | +- * 1. start at offset 0 (within the chunk), and read/write |
| 29 | +- * the entire chunk |
| 30 | +- * 2. start at offset 0 (within the chunk) and read/write less |
| 31 | +- * than entire chunk |
| 32 | +- * 3. start at an offset not equal to 0 and read/write the rest |
| 33 | ++ * 1. start at an offset not equal to 0 (within the chunk) |
| 34 | ++ * and read/write less than the rest of the chunk |
| 35 | ++ * 2. start at an offset not equal to 0 and read/write the rest |
| 36 | + * of the chunk |
| 37 | +- * 4. start at an offset not equal to 0 and read/write less than |
| 38 | +- * (end of chunk - offset) |
| 39 | ++ * 3. start at offset 0 (within the chunk) and read/write less |
| 40 | ++ * than entire chunk |
| 41 | ++ * 4. start at offset 0 (within the chunk), and read/write |
| 42 | ++ * the entire chunk |
| 43 | + */ |
| 44 | + chunk_start_offset = chunk * OPTOE_PAGE_SIZE; |
| 45 | ++ chunk_end_offset = chunk_start_offset + OPTOE_PAGE_SIZE; |
| 46 | + |
| 47 | + if (chunk_start_offset < off) { |
| 48 | + chunk_offset = off; |
| 49 | +- if ((off + pending_len) < (chunk_start_offset + |
| 50 | +- OPTOE_PAGE_SIZE)) |
| 51 | ++ if ((off + pending_len) < chunk_end_offset) |
| 52 | + chunk_len = pending_len; |
| 53 | + else |
| 54 | +- chunk_len = OPTOE_PAGE_SIZE - off; |
| 55 | ++ chunk_len = chunk_end_offset - off; |
| 56 | + } else { |
| 57 | + chunk_offset = chunk_start_offset; |
| 58 | +- if (pending_len > OPTOE_PAGE_SIZE) |
| 59 | +- chunk_len = OPTOE_PAGE_SIZE; |
| 60 | +- else |
| 61 | ++ if (pending_len < OPTOE_PAGE_SIZE) |
| 62 | + chunk_len = pending_len; |
| 63 | ++ else |
| 64 | ++ chunk_len = OPTOE_PAGE_SIZE; |
| 65 | + } |
| 66 | + |
| 67 | + dev_dbg(&client->dev, |
0 commit comments