Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-drm-fsl-dcu.git] / drivers / block / pktcdvd.c
index 7c95c762950fde3efa8253e134662f2db9fc739b..c0e89490e3d5c97427eaf2eeb15c42bb672b037f 100644 (file)
@@ -190,15 +190,6 @@ static struct attribute *kobj_pkt_attrs_wqueue[] = {
        NULL
 };
 
-/* declares a char buffer[64] _dbuf, copies data from
- * _b with length _l into it and ensures that _dbuf ends
- * with a \0 character.
- */
-#define DECLARE_BUF_AS_STRING(_dbuf, _b, _l) \
-       char _dbuf[64]; int dlen = (_l) < 0 ? 0 : (_l); \
-       if (dlen >= sizeof(_dbuf)) dlen = sizeof(_dbuf)-1; \
-       memcpy(_dbuf, _b, dlen); _dbuf[dlen] = 0
-
 static ssize_t kobj_pkt_show(struct kobject *kobj,
                        struct attribute *attr, char *data)
 {
@@ -264,9 +255,8 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
 {
        struct pktcdvd_device *pd = to_pktcdvdkobj(kobj)->pd;
        int val;
-       DECLARE_BUF_AS_STRING(dbuf, data, len); /* ensure sscanf scans a string */
 
-       if (strcmp(attr->name, "reset") == 0 && dlen > 0) {
+       if (strcmp(attr->name, "reset") == 0 && len > 0) {
                pd->stats.pkt_started = 0;
                pd->stats.pkt_ended = 0;
                pd->stats.secs_w = 0;
@@ -274,7 +264,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
                pd->stats.secs_r = 0;
 
        } else if (strcmp(attr->name, "congestion_off") == 0
-                  && sscanf(dbuf, "%d", &val) == 1) {
+                  && sscanf(data, "%d", &val) == 1) {
                spin_lock(&pd->lock);
                pd->write_congestion_off = val;
                init_write_congestion_marks(&pd->write_congestion_off,
@@ -282,7 +272,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
                spin_unlock(&pd->lock);
 
        } else if (strcmp(attr->name, "congestion_on") == 0
-                  && sscanf(dbuf, "%d", &val) == 1) {
+                  && sscanf(data, "%d", &val) == 1) {
                spin_lock(&pd->lock);
                pd->write_congestion_on = val;
                init_write_congestion_marks(&pd->write_congestion_off,
@@ -369,8 +359,7 @@ static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
                                        size_t count)
 {
        unsigned int major, minor;
-       DECLARE_BUF_AS_STRING(dbuf, buf, count);
-       if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
+       if (sscanf(buf, "%u:%u", &major, &minor) == 2) {
                pkt_setup_dev(MKDEV(major, minor), NULL);
                return count;
        }
@@ -381,8 +370,7 @@ static ssize_t class_pktcdvd_store_remove(struct class *c, const char *buf,
                                        size_t count)
 {
        unsigned int major, minor;
-       DECLARE_BUF_AS_STRING(dbuf, buf, count);
-       if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
+       if (sscanf(buf, "%u:%u", &major, &minor) == 2) {
                pkt_remove_dev(MKDEV(major, minor));
                return count;
        }
@@ -765,47 +753,34 @@ static inline struct bio *pkt_get_list_first(struct bio **list_head, struct bio
  */
 static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
 {
-       char sense[SCSI_SENSE_BUFFERSIZE];
-       request_queue_t *q;
+       request_queue_t *q = bdev_get_queue(pd->bdev);
        struct request *rq;
-       DECLARE_COMPLETION_ONSTACK(wait);
-       int err = 0;
+       int ret = 0;
 
-       q = bdev_get_queue(pd->bdev);
+       rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ?
+                            WRITE : READ, __GFP_WAIT);
+
+       if (cgc->buflen) {
+               if (blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen, __GFP_WAIT))
+                       goto out;
+       }
+
+       rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
+       memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
+       if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
+               memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
 
-       rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? WRITE : READ,
-                            __GFP_WAIT);
-       rq->errors = 0;
-       rq->rq_disk = pd->bdev->bd_disk;
-       rq->bio = NULL;
-       rq->buffer = NULL;
        rq->timeout = 60*HZ;
-       rq->data = cgc->buffer;
-       rq->data_len = cgc->buflen;
-       rq->sense = sense;
-       memset(sense, 0, sizeof(sense));
-       rq->sense_len = 0;
        rq->cmd_type = REQ_TYPE_BLOCK_PC;
        rq->cmd_flags |= REQ_HARDBARRIER;
        if (cgc->quiet)
                rq->cmd_flags |= REQ_QUIET;
-       memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
-       if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
-               memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
-       rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
-
-       rq->ref_count++;
-       rq->end_io_data = &wait;
-       rq->end_io = blk_end_sync_rq;
-       elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1);
-       generic_unplug_device(q);
-       wait_for_completion(&wait);
-
-       if (rq->errors)
-               err = -EIO;
 
+       blk_execute_rq(rq->q, pd->bdev->bd_disk, rq, 0);
+       ret = rq->errors;
+out:
        blk_put_request(rq);
-       return err;
+       return ret;
 }
 
 /*
@@ -1390,7 +1365,7 @@ try_next_bio:
                        && pd->bio_queue_size <= pd->write_congestion_off);
        spin_unlock(&pd->lock);
        if (wakeup)
-               blk_clear_queue_congested(pd->disk->queue, WRITE);
+               clear_bdi_congested(&pd->disk->queue->backing_dev_info, WRITE);
 
        pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
        pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2611,7 +2586,7 @@ static int pkt_make_request(request_queue_t *q, struct bio *bio)
        spin_lock(&pd->lock);
        if (pd->write_congestion_on > 0
            && pd->bio_queue_size >= pd->write_congestion_on) {
-               blk_set_queue_congested(q, WRITE);
+               set_bdi_congested(&q->backing_dev_info, WRITE);
                do {
                        spin_unlock(&pd->lock);
                        congestion_wait(WRITE, HZ);