summaryrefslogtreecommitdiff
path: root/drivers/scsi/scsi_debug.c
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2008-03-20 11:09:16 +0900
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-04-07 12:18:58 -0500
commit5cb2fc06107fe343a9488b32ddf3d9b4596b7090 (patch)
tree21545a47e33634903b1294e50b8b54260e87846d /drivers/scsi/scsi_debug.c
parentf3df41cff40992499d3c693251622299e4ce18c3 (diff)
downloadlwn-5cb2fc06107fe343a9488b32ddf3d9b4596b7090.tar.gz
lwn-5cb2fc06107fe343a9488b32ddf3d9b4596b7090.zip
[SCSI] scsi_debug: create new scsi_debug devices at a single place
Two functions, sdebug_add_adapter and devInfoReg, creates new scsi_debug devices. To simplify the code, this patch adds a new helper function to create new scsi_debug devices (sdebug_device_create) and converts both functions to use it. I plan to add more to scsi_debug devices (e.g. using a thread for a scsi_debug device for scalability testings). This patch enable me to add such to just the new helper function instead of touching two functions, sdebug_add_adapter and devInfoReg. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Acked-by: Douglas Gilbert <dougg@torque.net> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/scsi_debug.c')
-rw-r--r--drivers/scsi/scsi_debug.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 2a388d06094a..161af1ded888 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2014,6 +2014,19 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp)
}
}
+struct sdebug_dev_info *sdebug_device_create(struct sdebug_host_info *sdbg_host,
+ gfp_t flags)
+{
+ struct sdebug_dev_info *devip;
+
+ devip = kzalloc(sizeof(*devip), flags);
+ if (devip) {
+ devip->sdbg_host = sdbg_host;
+ list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list);
+ }
+ return devip;
+}
+
static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
{
struct sdebug_host_info * sdbg_host;
@@ -2038,16 +2051,13 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
open_devip = devip;
}
}
- if (NULL == open_devip) { /* try and make a new one */
- open_devip = kzalloc(sizeof(*open_devip),GFP_ATOMIC);
- if (NULL == open_devip) {
+ if (!open_devip) { /* try and make a new one */
+ open_devip = sdebug_device_create(sdbg_host, GFP_ATOMIC);
+ if (!open_devip) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
return NULL;
}
- open_devip->sdbg_host = sdbg_host;
- list_add_tail(&open_devip->dev_list,
- &sdbg_host->dev_info_list);
}
if (open_devip) {
open_devip->channel = sdev->channel;
@@ -2935,16 +2945,13 @@ static int sdebug_add_adapter(void)
devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns;
for (k = 0; k < devs_per_host; k++) {
- sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL);
- if (NULL == sdbg_devinfo) {
+ sdbg_devinfo = sdebug_device_create(sdbg_host, GFP_KERNEL);
+ if (!sdbg_devinfo) {
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
error = -ENOMEM;
goto clean;
}
- sdbg_devinfo->sdbg_host = sdbg_host;
- list_add_tail(&sdbg_devinfo->dev_list,
- &sdbg_host->dev_info_list);
}
spin_lock(&sdebug_host_list_lock);