From 1da1aa9dd4ad5a2f3a1ee5e5c043c867c65561e9 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 25 Aug 2011 18:08:45 +0000 Subject: [PATCH] Fix possible crash on rel_tgt_id set on transports without is_target_enabled() defined. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3831 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_sysfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 0b43981e9..eff55e1ce 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -2127,6 +2127,7 @@ static int scst_process_rel_tgt_id_store(struct scst_sysfs_work_item *work) int res = 0; struct scst_tgt *tgt = work->tgt_r; unsigned long rel_tgt_id = work->rel_tgt_id; + bool enabled; TRACE_ENTRY(); @@ -2135,8 +2136,12 @@ static int scst_process_rel_tgt_id_store(struct scst_sysfs_work_item *work) TRACE_DBG("Trying to set relative target port id %d", (uint16_t)rel_tgt_id); - if (tgt->tgtt->is_target_enabled(tgt) && - rel_tgt_id != tgt->rel_tgt_id) { + if (tgt->tgtt->is_target_enabled != NULL) + enabled = tgt->tgtt->is_target_enabled(tgt); + else + enabled = true; + + if (enabled && rel_tgt_id != tgt->rel_tgt_id) { if (!scst_is_relative_target_port_id_unique(rel_tgt_id, tgt)) { PRINT_ERROR("Relative port id %d is not unique", (uint16_t)rel_tgt_id); @@ -2147,7 +2152,7 @@ static int scst_process_rel_tgt_id_store(struct scst_sysfs_work_item *work) if (rel_tgt_id < SCST_MIN_REL_TGT_ID || rel_tgt_id > SCST_MAX_REL_TGT_ID) { - if ((rel_tgt_id == 0) && !tgt->tgtt->is_target_enabled(tgt)) + if ((rel_tgt_id == 0) && !enabled) goto set; PRINT_ERROR("Invalid relative port id %d",