All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 11/63] ide-cd: add ide_cd_pad_transfer() helper
Date: Thu, 20 Dec 2007 02:00:38 +0100	[thread overview]
Message-ID: <200712200200.38615.bzolnier@gmail.com> (raw)


Add ide_cd_pad_transfer() helper and use it in cdrom_[new]pc_intr()
and cdrom_{read,write}_check_ireason().

There should be no functionality changes caused by this patch.

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
-39 bytes
 drivers/ide/ide-cd.c |   51 +++++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

Index: b/drivers/ide/ide-cd.c
===================================================================
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1007,6 +1007,15 @@ static ide_startstop_t cdrom_transfer_pa
 
 typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
 
+static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
+{
+	while (len > 0) {
+		int dum = 0;
+		xf(drive, &dum, sizeof(dum));
+		len -= sizeof(dum);
+	}
+}
+
 /*
  * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector
  * buffer.  Once the first sector is added, any subsequent sectors are
@@ -1063,17 +1072,15 @@ int cdrom_read_check_ireason (ide_drive_
 	if (ireason == 2)
 		return 0;
 	else if (ireason == 0) {
+		ide_hwif_t *hwif = drive->hwif;
+
 		/* Whoops... The drive is expecting to receive data from us! */
 		printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
 				drive->name, __FUNCTION__);
 
 		/* Throw some data at the drive so it doesn't hang
 		   and quit this request. */
-		while (len > 0) {
-			int dum = 0;
-			HWIF(drive)->atapi_output_bytes(drive, &dum, sizeof (dum));
-			len -= sizeof (dum);
-		}
+		ide_cd_pad_transfer(drive, hwif->atapi_output_bytes, len);
 	} else  if (ireason == 1) {
 		/* Some drives (ASUS) seem to tell us that status
 		 * info is available. just get it and ignore.
@@ -1500,15 +1507,8 @@ static ide_startstop_t cdrom_pc_intr (id
 		/* Transfer the data. */
 		xferfunc(drive, rq->data, thislen);
 
-		/* If we haven't moved enough data to satisfy the drive,
-		   add some padding. */
-		while (len > thislen) {
-			int dum = 0;
-			xferfunc(drive, &dum, sizeof(dum));
-			len -= sizeof(dum);
-		}
-
 		/* Keep count of how much data we've moved. */
+		len -= thislen;
 		rq->data += thislen;
 		rq->data_len -= thislen;
 
@@ -1525,6 +1525,13 @@ confused:
 		return ide_stopped;
 	}
 
+	/*
+	 * If we haven't moved enough data to satisfy the drive,
+	 * add some padding.
+	 */
+	if (len > 0)
+		ide_cd_pad_transfer(drive, xferfunc, len);
+
 	/* Now we wait for another interrupt. */
 	ide_set_handler(drive, &cdrom_pc_intr, ATAPI_WAIT_PC, cdrom_timer_expiry);
 	return ide_started;
@@ -1617,15 +1624,13 @@ static int cdrom_write_check_ireason(ide
 	if (ireason == 0)
 		return 0;
 	else if (ireason == 2) {
+		ide_hwif_t *hwif = drive->hwif;
+
 		/* Whoops... The drive wants to send data. */
 		printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
 				drive->name, __FUNCTION__);
 
-		while (len > 0) {
-			int dum = 0;
-			HWIF(drive)->atapi_input_bytes(drive, &dum, sizeof(dum));
-			len -= sizeof(dum);
-		}
+		ide_cd_pad_transfer(drive, hwif->atapi_input_bytes, len);
 	} else {
 		/* Drive wants a command packet, or invalid ireason... */
 		printk(KERN_ERR "%s: %s: bad interrupt reason 0x02%x\n",
@@ -1754,14 +1759,8 @@ static ide_startstop_t cdrom_newpc_intr(
 	/*
 	 * pad, if necessary
 	 */
-	if (len > 0) {
-		while (len > 0) {
-			int pad = 0;
-
-			xferfunc(drive, &pad, sizeof(pad));
-			len -= sizeof(pad);
-		}
-	}
+	if (len > 0)
+		ide_cd_pad_transfer(drive, xferfunc, len);
 
 	BUG_ON(HWGROUP(drive)->handler != NULL);
 

                 reply	other threads:[~2007-12-20  1:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200712200200.38615.bzolnier@gmail.com \
    --to=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.