Commit 6b4fef7a authored by Martin Dalecki's avatar Martin Dalecki Committed by Linus Torvalds

[PATCH] 2.5.17 IDE 66

 - Move ll_10byte_cmd_build to the only place where it's used: ide-cd.  The SCSI
   layer does have it's own implementation which additionally it's messing
   around with the hard_nr_sectors struct request value.  One should *not*
   provide "infrastructure" until its really used as such.

   If anywhere this should reside in a file called ATAPI.

 - Unfold the INIT_REQUEST macro from blk.h. This showed up plenty of duplicate
   checks for QUEUE_EMPTY. Clean them as well. Remove the over cautious
   major(CURRENT->rq_dev != MAJOR_NR) checks. During the last several years I
   never saw any report about it. Looking at the !CURRENT->bio it is clear that
   dereferencing NULL will provide the same kind of panic as the check.  Some
   comments around the code in question show nicely that indeed INIT_REQUEST
   was a good example of code obfuscation.

 - A short look at RQ_INACTIVE shows that it is only used inside the scsi.c file
   and during the removal of devices. This shows that the many checks for
   RQ_INACTIVE are not necessary. Looking closer even shows that some of them
   did happen before checks for an empty queue. Plenty of drivers didn't care
   about it and the CD-ROM ones should be handled properly, because the
   most common drivers would fail as well. Comments indicate that this
   was an leftover from 1.3 days...
parent 69479390
......@@ -984,7 +984,10 @@ static void do_stram_request(request_queue_t *q)
unsigned long len;
while (1) {
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
start = swap_start + (CURRENT->sector << 9);
len = CURRENT->current_nr_sectors << 9;
......
......@@ -889,17 +889,6 @@ static void mfm_request(void)
{
DBG("mfm_request CURRENT=%p Busy=%d\n", CURRENT, Busy);
if (QUEUE_EMPTY) {
DBG("mfm_request: Exited due to NULL Current 1\n");
return;
}
if (CURRENT->rq_status == RQ_INACTIVE) {
/* Hmm - seems to be happening a lot on 1.3.45 */
/*console_printf("mfm_request: Exited due to INACTIVE Current\n"); */
return;
}
/* If we are still processing then return; we will get called again */
if (Busy) {
/* Again seems to be common in 1.3.45 */
......@@ -914,16 +903,14 @@ static void mfm_request(void)
DBG("mfm_request: loop start\n");
sti();
DBG("mfm_request: before INIT_REQUEST\n");
DBG("mfm_request: before blk_queue_empty\n");
if (QUEUE_EMPTY) {
printk("mfm_request: Exiting due to !CURRENT (pre)\n");
if (blk_queue_empty(QUEUE)) {
printk("mfm_request: Exiting due to empty queue (pre)\n");
CLEAR_INTR;
Busy = 0;
return;
};
INIT_REQUEST;
}
DBG("mfm_request: before arg extraction\n");
......
......@@ -523,42 +523,6 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
printk("\n");
}
/*
* standard prep_rq_fn that builds 10 byte cmds
*/
int ll_10byte_cmd_build(request_queue_t *q, struct request *rq)
{
int hard_sect = queue_hardsect_size(q);
sector_t block = rq->hard_sector / (hard_sect >> 9);
unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9);
if (!(rq->flags & REQ_CMD))
return 0;
memset(rq->cmd, 0, sizeof(rq->cmd));
if (rq_data_dir(rq) == READ)
rq->cmd[0] = READ_10;
else
rq->cmd[0] = WRITE_10;
/*
* fill in lba
*/
rq->cmd[2] = (block >> 24) & 0xff;
rq->cmd[3] = (block >> 16) & 0xff;
rq->cmd[4] = (block >> 8) & 0xff;
rq->cmd[5] = block & 0xff;
/*
* and transfer length
*/
rq->cmd[7] = (blocks >> 8) & 0xff;
rq->cmd[8] = blocks & 0xff;
return 0;
}
void blk_recount_segments(request_queue_t *q, struct bio *bio)
{
struct bio_vec *bv, *bvprv = NULL;
......@@ -1765,9 +1729,8 @@ inline void blk_recalc_rq_sectors(struct request *rq, int nsect)
{
if (rq->flags & REQ_CMD) {
rq->hard_sector += nsect;
rq->hard_nr_sectors -= nsect;
rq->nr_sectors = rq->hard_nr_sectors -= nsect;
rq->sector = rq->hard_sector;
rq->nr_sectors = rq->hard_nr_sectors;
rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
rq->hard_cur_sectors = rq->current_nr_sectors;
......@@ -1944,7 +1907,6 @@ EXPORT_SYMBOL(blk_queue_assign_lock);
EXPORT_SYMBOL(blk_phys_contig_segment);
EXPORT_SYMBOL(blk_hw_contig_segment);
EXPORT_SYMBOL(ll_10byte_cmd_build);
EXPORT_SYMBOL(blk_queue_prep_rq);
EXPORT_SYMBOL(blk_queue_init_tags);
......
......@@ -760,8 +760,11 @@ static void do_pcd_request (request_queue_t * q)
if (pcd_busy) return;
while (1) {
if (QUEUE_EMPTY || (CURRENT->rq_status == RQ_INACTIVE)) return;
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (rq_data_dir(CURRENT) == READ) {
unit = minor(CURRENT->rq_dev);
if (unit != pcd_unit) {
......
......@@ -835,8 +835,10 @@ static void do_pd_request (request_queue_t * q)
if (pd_busy) return;
repeat:
if (QUEUE_EMPTY || (CURRENT->rq_status == RQ_INACTIVE)) return;
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
pd_dev = minor(CURRENT->rq_dev);
pd_unit = unit = DEVICE_NR(CURRENT->rq_dev);
......
......@@ -841,8 +841,10 @@ static void do_pf_request (request_queue_t * q)
if (pf_busy) return;
repeat:
if (QUEUE_EMPTY || (CURRENT->rq_status == RQ_INACTIVE)) return;
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
pf_unit = unit = DEVICE_NR(CURRENT->rq_dev);
pf_block = CURRENT->sector;
......
......@@ -471,9 +471,12 @@ static void do_ps2esdi_request(request_queue_t * q)
CURRENT->current_nr_sectors, CURRENT->buffer);
#endif
/* standard macro that ensures that requests are really on the
/* standard procedure to ensure that requests are really on the
list + sanity checks. */
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (isa_virt_to_bus(CURRENT->buffer + CURRENT->current_nr_sectors * 512) > 16 * MB) {
printk("%s: DMA above 16MB not supported\n", DEVICE_NAME);
......
......@@ -279,8 +279,13 @@ static void do_xd_request (request_queue_t * q)
sti();
if (xdc_busy)
return;
while (code = 0, !QUEUE_EMPTY) {
INIT_REQUEST; /* do some checking on the request structure */
while (1) {
code = 0;
/* do some checking on the request structure */
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (CURRENT_DEV < xd_drives
&& (CURRENT->flags & REQ_CMD)
......
......@@ -76,7 +76,10 @@ do_z2_request( request_queue_t * q )
while ( TRUE )
{
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
start = CURRENT->sector << 9;
len = CURRENT->current_nr_sectors << 9;
......
......@@ -1598,7 +1598,8 @@ static void do_cdu31a_request(request_queue_t * q)
* The beginning here is stolen from the hard disk driver. I hope
* it's right.
*/
if (QUEUE_EMPTY || CURRENT->rq_status == RQ_INACTIVE) {
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
goto end_do_cdu31a_request;
}
......@@ -1606,8 +1607,6 @@ static void do_cdu31a_request(request_queue_t * q)
scd_spinup();
}
INIT_REQUEST;
block = CURRENT->sector;
nblock = CURRENT->nr_sectors;
......
......@@ -856,9 +856,11 @@ static void do_cm206_request(request_queue_t * q)
uch *source, *dest;
while (1) { /* repeat until all requests have been satisfied */
INIT_REQUEST;
if (QUEUE_EMPTY || CURRENT->rq_status == RQ_INACTIVE)
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (CURRENT->cmd != READ) {
debug(("Non-read command %d on cdrom\n",
CURRENT->cmd));
......
......@@ -279,9 +279,11 @@ static void __do_gscd_request(unsigned long dummy)
unsigned int nsect;
repeat:
if (QUEUE_EMPTY || CURRENT->rq_status == RQ_INACTIVE)
goto out;
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
dev = minor(CURRENT->rq_dev);
block = CURRENT->sector;
nsect = CURRENT->nr_sectors;
......
......@@ -562,19 +562,11 @@ void do_mcdx_request(request_queue_t * q)
again:
if (QUEUE_EMPTY) {
xtrace(REQUEST, "end_request(0): CURRENT == NULL\n");
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (CURRENT->rq_status == RQ_INACTIVE) {
xtrace(REQUEST,
"end_request(0): rq_status == RQ_INACTIVE\n");
return;
}
INIT_REQUEST;
dev = minor(CURRENT->rq_dev);
stuffp = mcdx_stuffp[dev];
......
......@@ -4915,12 +4915,15 @@ static void DO_SBPCD_REQUEST(request_queue_t * q)
printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
xnr, CURRENT, CURRENT->sector, CURRENT->nr_sectors, current->pid, jiffies);
#endif
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
req=CURRENT; /* take out our request so no other */
blkdev_dequeue_request(req); /* task can fuck it up GTL */
if (req->rq_status == RQ_INACTIVE)
sbpcd_end_request(req, 0);
if (req -> sector == -1)
sbpcd_end_request(req, 0);
spin_unlock_irq(q->queue_lock);
......
......@@ -806,10 +806,11 @@ do_cdu535_request(request_queue_t * q)
* The beginning here is stolen from the hard disk driver. I hope
* it's right.
*/
if (QUEUE_EMPTY || CURRENT->rq_status == RQ_INACTIVE) {
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
INIT_REQUEST;
dev = minor(CURRENT->rq_dev);
block = CURRENT->sector;
nsect = CURRENT->nr_sectors;
......
......@@ -544,13 +544,17 @@ static void hd_request(void)
{
unsigned int dev, block, nsect, sec, track, head, cyl;
if (!QUEUE_EMPTY && CURRENT->rq_status == RQ_INACTIVE) return;
if (DEVICE_INTR)
return;
repeat:
del_timer(&device_timer);
sti();
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
if (reset) {
cli();
reset_hd();
......
......@@ -2658,6 +2658,47 @@ int ide_cdrom_probe_capabilities(struct ata_device *drive)
return nslots;
}
/*
* standard prep_rq_fn that builds 10 byte cmds
*/
static int ll_10byte_cmd_build(request_queue_t *q, struct request *rq)
{
int hard_sect = queue_hardsect_size(q);
sector_t block = rq->hard_sector / (hard_sect >> 9);
unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9);
if (!(rq->flags & REQ_CMD))
return 0;
if (rq->hard_nr_sectors != rq->nr_sectors) {
printk(KERN_ERR "ide-cd: hard_nr_sectors differs from nr_sectors! %lu %lu\n",
rq->nr_sectors, rq->hard_nr_sectors);
}
memset(rq->cmd, 0, sizeof(rq->cmd));
if (rq_data_dir(rq) == READ)
rq->cmd[0] = GPCMD_READ_10;
else
rq->cmd[0] = GPCMD_WRITE_10;
/*
* fill in lba
*/
rq->cmd[2] = (block >> 24) & 0xff;
rq->cmd[3] = (block >> 16) & 0xff;
rq->cmd[4] = (block >> 8) & 0xff;
rq->cmd[5] = block & 0xff;
/*
* and transfer length
*/
rq->cmd[7] = (blocks >> 8) & 0xff;
rq->cmd[8] = blocks & 0xff;
return 0;
}
static int ide_cdrom_setup(struct ata_device *drive)
{
struct cdrom_info *info = drive->driver_data;
......
......@@ -1192,7 +1192,10 @@ static void do_ftl_request(request_arg_t)
do {
// sti();
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
minor = minor(CURRENT->rq_dev);
......
......@@ -405,7 +405,11 @@ static void handle_mtdblock_request(void)
unsigned int res;
for (;;) {
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
req = CURRENT;
spin_unlock_irq(QUEUE->queue_lock);
mtdblk = mtdblks[minor(req->rq_dev)];
......
......@@ -112,9 +112,13 @@ static void mtdblock_request(RQFUNC_ARG)
while (1)
{
/* Grab the Request and unlink it from the request list, INIT_REQUEST
/* Grab the Request and unlink it from the request list, we
will execute a return if we are done. */
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
current_request = CURRENT;
if (minor(current_request->rq_dev) >= MAX_MTD_DEVICES)
......
......@@ -837,7 +837,11 @@ void nftl_request(RQFUNC_ARG)
int res;
while (1) {
INIT_REQUEST; /* blk.h */
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
req = CURRENT;
/* We can do this because the generic code knows not to
......
......@@ -747,7 +747,10 @@ void xpram_request(request_queue_t * queue)
#endif /* V24 */
while(1) {
INIT_REQUEST;
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
fault=0;
#if ( XPRAM_VERSION == 24 )
......
......@@ -207,7 +207,11 @@ static void jsfd_do_request(request_queue_t *q)
size_t len;
for (;;) {
INIT_REQUEST; /* if (QUEUE_EMPTY) return; */
if (blk_queue_empty(QUEUE)) {
CLEAR_INTR;
return;
}
req = CURRENT;
dev = MINOR(req->rq_dev);
......
......@@ -313,22 +313,11 @@ static void (*DEVICE_INTR)(void) = NULL;
#define SET_INTR(x) (DEVICE_INTR = (x))
#ifdef DEVICE_INTR
#define CLEAR_INTR SET_INTR(NULL)
#else
#define CLEAR_INTR
#endif
#define INIT_REQUEST \
if (QUEUE_EMPTY) { \
CLEAR_INTR; \
return; \
} \
if (major(CURRENT->rq_dev) != MAJOR_NR) \
panic(DEVICE_NAME ": request list destroyed"); \
if (!CURRENT->bio) \
panic(DEVICE_NAME ": no bio"); \
# ifdef DEVICE_INTR
# define CLEAR_INTR SET_INTR(NULL)
# else
# define CLEAR_INTR
# endif
#endif /* !defined(IDE_DRIVER) */
/*
......
......@@ -303,7 +303,6 @@ extern void blk_recount_segments(request_queue_t *, struct bio *);
extern inline int blk_phys_contig_segment(request_queue_t *q, struct bio *, struct bio *);
extern inline int blk_hw_contig_segment(request_queue_t *q, struct bio *, struct bio *);
extern int block_ioctl(struct block_device *, unsigned int, unsigned long);
extern int ll_10byte_cmd_build(request_queue_t *, struct request *);
/*
* get ready for proper ref counting
......
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