#define BSG_DESCRIPTION        "Block layer SCSI generic (bsg) driver"
 #define BSG_VERSION    "0.4"
 
+#define bsg_dbg(bd, fmt, ...) \
+       pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
+
 struct bsg_device {
        struct request_queue *queue;
        spinlock_t lock;
 #define BSG_DEFAULT_CMDS       64
 #define BSG_MAX_DEVS           32768
 
-#undef BSG_DEBUG
-
-#ifdef BSG_DEBUG
-#define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ##args)
-#else
-#define dprintk(fmt, args...)
-#endif
-
 static DEFINE_MUTEX(bsg_mutex);
 static DEFINE_IDR(bsg_minor_idr);
 
 
        bc->bd = bd;
        INIT_LIST_HEAD(&bc->list);
-       dprintk("%s: returning free cmd %p\n", bd->name, bc);
+       bsg_dbg(bd, "returning free cmd %p\n", bc);
        return bc;
 out:
        spin_unlock_irq(&bd->lock);
        if (!bcd->class_dev)
                return ERR_PTR(-ENXIO);
 
-       dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr->dout_xferp,
+       bsg_dbg(bd, "map hdr %llx/%u %llx/%u\n",
+               (unsigned long long) hdr->dout_xferp,
                hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
                hdr->din_xfer_len);
 
        struct bsg_device *bd = bc->bd;
        unsigned long flags;
 
-       dprintk("%s: finished rq %p bc %p, bio %p\n",
-               bd->name, rq, bc, bc->bio);
+       bsg_dbg(bd, "finished rq %p bc %p, bio %p\n",
+               rq, bc, bc->bio);
 
        bc->hdr.duration = jiffies_to_msecs(jiffies - bc->hdr.duration);
 
        list_add_tail(&bc->list, &bd->busy_list);
        spin_unlock_irq(&bd->lock);
 
-       dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
+       bsg_dbg(bd, "queueing rq %p, bc %p\n", rq, bc);
 
        rq->end_io_data = bc;
        blk_execute_rq_nowait(q, NULL, rq, at_head, bsg_rq_end_io);
                }
        } while (1);
 
-       dprintk("%s: returning done %p\n", bd->name, bc);
+       bsg_dbg(bd, "returning done %p\n", bc);
 
        return bc;
 }
        struct scsi_request *req = scsi_req(rq);
        int ret = 0;
 
-       dprintk("rq %p bio %p 0x%x\n", rq, bio, req->result);
+       pr_debug("rq %p bio %p 0x%x\n", rq, bio, req->result);
        /*
         * fill in all the output members
         */
        struct bsg_command *bc;
        int ret, tret;
 
-       dprintk("%s: entered\n", bd->name);
+       bsg_dbg(bd, "entered\n");
 
        /*
         * wait for all commands to complete
        int ret;
        ssize_t bytes_read;
 
-       dprintk("%s: read %zd bytes\n", bd->name, count);
+       bsg_dbg(bd, "read %zd bytes\n", count);
 
        bsg_set_block(bd, file);
 
        ssize_t bytes_written;
        int ret;
 
-       dprintk("%s: write %zd bytes\n", bd->name, count);
+       bsg_dbg(bd, "write %zd bytes\n", count);
 
        if (unlikely(uaccess_kernel()))
                return -EINVAL;
        if (!bytes_written || err_block_err(ret))
                bytes_written = ret;
 
-       dprintk("%s: returning %zd\n", bd->name, bytes_written);
+       bsg_dbg(bd, "returning %zd\n", bytes_written);
        return bytes_written;
 }
 
        hlist_del(&bd->dev_list);
        mutex_unlock(&bsg_mutex);
 
-       dprintk("%s: tearing down\n", bd->name);
+       bsg_dbg(bd, "tearing down\n");
 
        /*
         * close can always block
                                         struct file *file)
 {
        struct bsg_device *bd;
-#ifdef BSG_DEBUG
        unsigned char buf[32];
-#endif
 
        if (!blk_queue_scsi_passthrough(rq)) {
                WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
        hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
 
        strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
-       dprintk("bound to <%s>, max queue %d\n",
+       bsg_dbg(bd, "bound to <%s>, max queue %d\n",
                format_dev_t(buf, inode->i_rdev), bd->max_queue);
 
        mutex_unlock(&bsg_mutex);