ide-cd: prepare cdrom_rw_intr() and cdrom_newpc_intr() to be merged

In cdrom_newpc_intr():
* cleanup variables in the 'transfer data' loop

In cdrom_rw_intr():
* rename 'sectors_to_transfer' to 'thislen'
* rename 'this_transfer' to 'blen'
* keep number of bytes (instead of sectors) in 'thislen' and 'blen'
* call 'xferfunc' only once for 'blen'
* cache 'rq->buffer' in 'ptr' variable
* check for 'rq->bio' before setting 'ptr' and 'blen'
* check for 'ptr' instead of 'rq->current_nr_sectors'

There should be no functionality changes caused by this patch.
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 37782fce
...@@ -1123,8 +1123,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) ...@@ -1123,8 +1123,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
* transfer data * transfer data
*/ */
while (thislen > 0) { while (thislen > 0) {
int blen = blen = rq->data_len; u8 *ptr = rq->data;
char *ptr = rq->data; int blen = rq->data_len;
/* /*
* bio backed? * bio backed?
...@@ -1207,7 +1207,7 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) ...@@ -1207,7 +1207,7 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive)
struct cdrom_info *info = drive->driver_data; struct cdrom_info *info = drive->driver_data;
struct request *rq = HWGROUP(drive)->rq; struct request *rq = HWGROUP(drive)->rq;
xfer_func_t *xferfunc; xfer_func_t *xferfunc;
int stat, ireason, len, sectors_to_transfer, uptodate, nskip; int stat, ireason, len, thislen, uptodate, nskip;
int dma_error = 0, dma = info->dma, write = rq_data_dir(rq) == WRITE; int dma_error = 0, dma = info->dma, write = rq_data_dir(rq) == WRITE;
u8 lowcyl = 0, highcyl = 0; u8 lowcyl = 0, highcyl = 0;
...@@ -1262,7 +1262,7 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) ...@@ -1262,7 +1262,7 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive)
return ide_stopped; return ide_stopped;
} }
sectors_to_transfer = len / SECTOR_SIZE; thislen = len;
/* Check that the drive is expecting to do the same thing we are. */ /* Check that the drive is expecting to do the same thing we are. */
if (write) { if (write) {
...@@ -1285,12 +1285,12 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) ...@@ -1285,12 +1285,12 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive)
*/ */
nskip = min_t(int, rq->current_nr_sectors nskip = min_t(int, rq->current_nr_sectors
- bio_cur_sectors(rq->bio), - bio_cur_sectors(rq->bio),
sectors_to_transfer); thislen >> 9);
if (nskip > 0) { if (nskip > 0) {
ide_cd_drain_data(drive, nskip); ide_cd_drain_data(drive, nskip);
rq->current_nr_sectors -= nskip; rq->current_nr_sectors -= nskip;
sectors_to_transfer -= nskip; thislen -= (nskip << 9);
} }
xferfunc = HWIF(drive)->atapi_input_bytes; xferfunc = HWIF(drive)->atapi_input_bytes;
...@@ -1299,17 +1299,23 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) ...@@ -1299,17 +1299,23 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive)
/* /*
* now loop and read/write the data * now loop and read/write the data
*/ */
while (sectors_to_transfer > 0) { while (thislen > 0) {
int this_transfer; u8 *ptr = NULL;
int blen;
if (rq->bio) {
ptr = rq->buffer;
blen = rq->current_nr_sectors << 9;
}
if (!rq->current_nr_sectors) { if (!ptr) {
if (!write) if (!write)
/* /*
* If the buffers are full, cache the rest * If the buffers are full, cache the rest
* of the data in our internal buffer. * of the data in our internal buffer.
*/ */
cdrom_buffer_sectors(drive, rq->sector, cdrom_buffer_sectors(drive, rq->sector,
sectors_to_transfer); thislen >> 9);
else else
printk(KERN_ERR "%s: %s: confused, missing " printk(KERN_ERR "%s: %s: confused, missing "
"data\n", "data\n",
...@@ -1320,17 +1326,16 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive) ...@@ -1320,17 +1326,16 @@ static ide_startstop_t cdrom_rw_intr(ide_drive_t *drive)
/* /*
* Figure out how many sectors we can transfer * Figure out how many sectors we can transfer
*/ */
this_transfer = min_t(int, sectors_to_transfer, rq->current_nr_sectors); if (blen > thislen)
blen = thislen;
while (this_transfer > 0) { xferfunc(drive, ptr, blen);
xferfunc(drive, rq->buffer, SECTOR_SIZE);
rq->buffer += SECTOR_SIZE; thislen -= blen;
--rq->nr_sectors; rq->buffer += blen;
--rq->current_nr_sectors; rq->nr_sectors -= (blen >> 9);
++rq->sector; rq->current_nr_sectors -= (blen >> 9);
--this_transfer; rq->sector += (blen >> 9);
--sectors_to_transfer;
}
/* /*
* current buffer complete, move on * current buffer complete, move on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment