Skip to content

Commit 746d5e4

Browse files
Borislav Petkovhtejun
authored andcommitted
ide-cd: convert to using generic sense request
Preallocate a sense request in the ->do_request method and reinitialize it only on demand, in case it's been consumed in the IRQ handler path. The reason for this is that we don't want to be mapping rq to bio in the IRQ path and introduce all kinds of unnecessary hacks to the block layer. tj: * Both user and kernel PC requests expect sense data to be stored in separate storage other than drive->sense_data. Copy sense data to rq->sense on completion if rq->sense is not NULL. This fixes bogus sense data on PC requests. As a result, remove cdrom_queue_request_sense. CC: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> CC: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent a1df516 commit 746d5e4

2 files changed

Lines changed: 12 additions & 46 deletions

File tree

‎drivers/ide/ide-cd.c‎

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -206,56 +206,23 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
206206
ide_cd_log_error(drive->name, failed_command, sense);
207207
}
208208

209-
static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
210-
struct request *failed_command)
211-
{
212-
struct cdrom_info *info = drive->driver_data;
213-
struct request *rq = &drive->request_sense_rq;
214-
215-
ide_debug_log(IDE_DBG_SENSE, "enter");
216-
217-
if (sense == NULL)
218-
sense = &info->sense_data;
219-
220-
memset(sense, 0, 18);
221-
222-
/* stuff the sense request in front of our current request */
223-
blk_rq_init(NULL, rq);
224-
rq->cmd_type = REQ_TYPE_ATA_PC;
225-
rq->rq_disk = info->disk;
226-
227-
rq->data = sense;
228-
rq->cmd[0] = GPCMD_REQUEST_SENSE;
229-
rq->cmd[4] = 18;
230-
rq->data_len = 18;
231-
232-
rq->cmd_type = REQ_TYPE_SENSE;
233-
rq->cmd_flags |= REQ_PREEMPT;
234-
235-
/* NOTE! Save the failed command in "rq->special" */
236-
rq->special = (void *)failed_command;
237-
238-
if (failed_command)
239-
ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x",
240-
failed_command->cmd[0]);
241-
242-
drive->hwif->rq = NULL;
243-
244-
elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
245-
}
246-
247209
static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
248210
{
249211
/*
250212
* For REQ_TYPE_SENSE, "rq->special" points to the original
251213
* failed request
252214
*/
253215
struct request *failed = (struct request *)rq->special;
254-
struct cdrom_info *info = drive->driver_data;
255-
void *sense = &info->sense_data;
216+
struct request_sense *sense = &drive->sense_data;
256217

257218
if (failed) {
258219
if (failed->sense) {
220+
/*
221+
* Sense is always read into drive->sense_data.
222+
* Copy back if the failed request has its
223+
* sense pointer set.
224+
*/
225+
memcpy(failed->sense, sense, 18);
259226
sense = failed->sense;
260227
failed->sense_len = rq->sense_len;
261228
}
@@ -431,7 +398,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
431398

432399
/* if we got a CHECK_CONDITION status, queue a request sense command */
433400
if (stat & ATA_ERR)
434-
cdrom_queue_request_sense(drive, NULL, NULL);
401+
ide_queue_sense_rq(drive, NULL);
435402
return 1;
436403

437404
end_request:
@@ -445,7 +412,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
445412

446413
hwif->rq = NULL;
447414

448-
cdrom_queue_request_sense(drive, rq->sense, rq);
415+
ide_queue_sense_rq(drive, rq);
449416
return 1;
450417
} else
451418
return 2;
@@ -893,6 +860,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
893860
goto out_end;
894861
}
895862

863+
/* prepare sense request for this command */
864+
ide_prep_sense(drive, rq);
865+
896866
memset(&cmd, 0, sizeof(cmd));
897867

898868
if (rq_data_dir(rq))

‎drivers/ide/ide-cd.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ struct cdrom_info {
8787

8888
struct atapi_toc *toc;
8989

90-
/* The result of the last successful request sense command
91-
on this device. */
92-
struct request_sense sense_data;
93-
9490
u8 max_speed; /* Max speed of the drive. */
9591
u8 current_speed; /* Current speed of the drive. */
9692

0 commit comments

Comments
 (0)