Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754041AbZAZSTk (ORCPT ); Mon, 26 Jan 2009 13:19:40 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752182AbZAZSTQ (ORCPT ); Mon, 26 Jan 2009 13:19:16 -0500 Received: from moutng.kundenserver.de ([212.227.126.187]:56082 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752000AbZAZSTP (ORCPT ); Mon, 26 Jan 2009 13:19:15 -0500 Message-ID: <497DFEA9.20605@vlnb.net> Date: Mon, 26 Jan 2009 21:19:21 +0300 From: Vladislav Bolkhovitin User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: linux-scsi@vger.kernel.org CC: linux-kernel@vger.kernel.org, scst-devel@lists.sourceforge.net Subject: [PATCH][SCST]: Minor cleanup in scst_user module with aim to have more robust code Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX19pn5Rk/rNtRSZBKVrf5UHMhsP8llvacaqB3ad XKqaFp/voyWBmuBXSd396o8e1sFQLFDEnMZyvtzUBKbuaYE5jQ G18NaT/YqYz/584blf8sQ== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5034 Lines: 121 This patch does a minor cleanup with aim to have more robust code Signed-off-by: Vladislav Bolkhovitin scst_user.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) Index: scst/src/dev_handlers/scst_user.c =================================================================== --- scst/src/dev_handlers/scst_user.c (revision 641) +++ scst/src/dev_handlers/scst_user.c (working copy) @@ -57,8 +57,6 @@ #define DEV_USER_CMD_HASH_ORDER 6 #define DEV_USER_ATTACH_TIMEOUT (5*HZ) -#define DEV_USER_HEADER_LEN offsetof(struct scst_user_get_cmd, preply) - struct scst_user_dev { struct rw_semaphore dev_rwsem; @@ -412,7 +410,9 @@ static void dev_user_on_cached_mem_free( TRACE_MEM("Preparing ON_CACHED_MEM_FREE (ucmd %p, h %d, ubuff %lx)", ucmd, ucmd->h, ucmd->ubuff); - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.on_cached_mem_free); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, on_cached_mem_free) + + sizeof(ucmd->user_cmd.on_cached_mem_free); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_ON_CACHED_MEM_FREE; ucmd->user_cmd.on_cached_mem_free.pbuf = ucmd->ubuff; @@ -630,7 +630,9 @@ static int dev_user_alloc_space(struct s goto out; } - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.alloc_cmd); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, alloc_cmd) + + sizeof(ucmd->user_cmd.alloc_cmd); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_ALLOC_MEM; ucmd->user_cmd.alloc_cmd.sess_h = (unsigned long)cmd->tgt_dev; @@ -751,7 +753,9 @@ static int dev_user_parse(struct scst_cm case SCST_USER_PARSE_CALL: TRACE_DBG("Preparing PARSE for user space (ucmd=%p, h=%d, " "bufflen %d)", ucmd, ucmd->h, cmd->bufflen); - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.parse_cmd); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, parse_cmd) + + sizeof(ucmd->user_cmd.parse_cmd); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_PARSE; ucmd->user_cmd.parse_cmd.sess_h = (unsigned long)cmd->tgt_dev; @@ -863,7 +867,9 @@ static int dev_user_exec(struct scst_cmd if (cmd->data_direction == SCST_DATA_WRITE) dev_user_flush_dcache(ucmd); - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.exec_cmd); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, exec_cmd) + + sizeof(ucmd->user_cmd.exec_cmd); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_EXEC; ucmd->user_cmd.exec_cmd.sess_h = (unsigned long)cmd->tgt_dev; @@ -932,7 +938,9 @@ static void dev_user_on_free_cmd(struct goto out_reply; } - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.on_free_cmd); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, on_free_cmd) + + sizeof(ucmd->user_cmd.on_free_cmd); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_ON_FREE_CMD; ucmd->user_cmd.on_free_cmd.pbuf = ucmd->ubuff; @@ -1730,12 +1739,15 @@ static int dev_user_reply_get_cmd(struct EXTRACHECKS_BUG_ON(ucmd->user_cmd_payload_len == 0); - len = DEV_USER_HEADER_LEN + ucmd->user_cmd_payload_len; + len = ucmd->user_cmd_payload_len; TRACE_DBG("ucmd %p (user_cmd %p), payload_len %d (len %d)", ucmd, &ucmd->user_cmd, ucmd->user_cmd_payload_len, len); TRACE_BUFFER("UCMD", &ucmd->user_cmd, len); @@ -2168,7 +2180,9 @@ static int dev_user_task_mgmt_fn(struct /* We can't afford missing TM command due to memory shortage */ ucmd = dev_user_alloc_ucmd(dev, GFP_KERNEL|__GFP_NOFAIL); - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.tm_cmd); + ucmd->user_cmd_payload_len = + offsetof(struct scst_user_get_cmd, tm_cmd) + + sizeof(ucmd->user_cmd.tm_cmd); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_TASK_MGMT; ucmd->user_cmd.tm_cmd.sess_h = (unsigned long)tgt_dev; @@ -2303,7 +2317,8 @@ static int dev_user_attach_tgt(struct sc ucmd->cmpl = &cmpl; - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.sess); + ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, sess) + + sizeof(ucmd->user_cmd.sess); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_ATTACH_SESS; ucmd->user_cmd.sess.sess_h = (unsigned long)tgt_dev; @@ -2380,7 +2395,8 @@ static void dev_user_detach_tgt(struct s TRACE_MGMT_DBG("Preparing DETACH_SESS %p (h %d, sess_h %llx)", ucmd, ucmd->h, ucmd->user_cmd.sess.sess_h); - ucmd->user_cmd_payload_len = sizeof(ucmd->user_cmd.sess); + ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, sess) + + sizeof(ucmd->user_cmd.sess); ucmd->user_cmd.cmd_h = ucmd->h; ucmd->user_cmd.subcode = SCST_USER_DETACH_SESS; ucmd->user_cmd.sess.sess_h = (unsigned long)tgt_dev; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/