Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target: move the dereference below the NULL test

The dereference should be moved below the NULL test.

spatch with a semantic match is used to found this.
(http://coccinelle.lip6.fr/)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Wei Yongjun and committed by
Nicholas Bellinger
609234e3 7875f179

+6 -4
+6 -4
drivers/target/target_core_pr.c
··· 197 197 { 198 198 struct se_device *dev = cmd->se_dev; 199 199 struct se_session *sess = cmd->se_sess; 200 - struct se_portal_group *tpg = sess->se_tpg; 200 + struct se_portal_group *tpg; 201 201 int ret = 0, rc; 202 202 203 - if (!sess || !tpg) 203 + if (!sess || !sess->se_tpg) 204 204 goto out; 205 205 rc = target_check_scsi2_reservation_conflict(cmd); 206 206 if (rc == 1) ··· 228 228 dev->dev_res_bin_isid = 0; 229 229 dev->dev_flags &= ~DF_SPC2_RESERVATIONS_WITH_ISID; 230 230 } 231 + tpg = sess->se_tpg; 231 232 pr_debug("SCSI-2 Released reservation for %s LUN: %u ->" 232 233 " MAPPED LUN: %u for %s\n", tpg->se_tpg_tfo->get_fabric_name(), 233 234 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun, ··· 246 245 { 247 246 struct se_device *dev = cmd->se_dev; 248 247 struct se_session *sess = cmd->se_sess; 249 - struct se_portal_group *tpg = sess->se_tpg; 248 + struct se_portal_group *tpg; 250 249 int ret = 0, rc; 251 250 252 251 if ((cmd->t_task_cdb[1] & 0x01) && ··· 261 260 * This is currently the case for target_core_mod passthrough struct se_cmd 262 261 * ops 263 262 */ 264 - if (!sess || !tpg) 263 + if (!sess || !sess->se_tpg) 265 264 goto out; 266 265 rc = target_check_scsi2_reservation_conflict(cmd); 267 266 if (rc == 1) ··· 273 272 } 274 273 275 274 ret = 0; 275 + tpg = sess->se_tpg; 276 276 spin_lock(&dev->dev_reservation_lock); 277 277 if (dev->dev_reserved_node_acl && 278 278 (dev->dev_reserved_node_acl != sess->se_node_acl)) {