From patchwork Sun Oct 9 13:30:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Syromyatnikov X-Patchwork-Id: 9369101 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 47FEA60865 for ; Mon, 10 Oct 2016 08:32:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3950229325 for ; Mon, 10 Oct 2016 08:32:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E1392932F; Mon, 10 Oct 2016 08:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ADE6E2933E for ; Mon, 10 Oct 2016 08:32:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9A8UfeF036820; Mon, 10 Oct 2016 04:30:41 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u99DUBZj016605 for ; Sun, 9 Oct 2016 09:30:11 -0400 Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u99DUBqL005244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 9 Oct 2016 09:30:11 -0400 Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F3327DD06; Sun, 9 Oct 2016 13:30:10 +0000 (UTC) Received: by mail-lf0-f67.google.com with SMTP id p80so5473031lfp.1; Sun, 09 Oct 2016 06:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9qK81GuFXOhoUpfxVhGYuA+ArGs6zcC/DoS/bD4QOvA=; b=Vun6r8hFiU+HRvELGM8VtCzC+O0U4Y08tq1u5S9fKyYOvbv0a3k6HdHV6lzQjSXG2r 9n7VjU7fMaaKnPHQOrSQ13OThg0ijWiR+uq9M2odEt0Sa5OhEn8k06pc1n+pihRpX3Wu e+V0Eo7RQr/PBGWzxMDfdPWKEpVJVVN1FZsvA2VcgkMFyxH7DLz/XN0FpEPu9q9xfNg5 RvF+PFb9OyGIdfieCsI4I+oRUsL64yFBJCdggR7HVzTu4R+x3K3TOb95mFjSD9e4RoN0 PaO9DZyb8Kxrg2eLLC1UUd7nDtazXBAV+vnK6UbiH2DW68dp6zjl2wMfKPRtcbDbCfb+ WfPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9qK81GuFXOhoUpfxVhGYuA+ArGs6zcC/DoS/bD4QOvA=; b=AEk8QRqBOtB23p1zmd68xZaENlRuCuVUpCsuOfMRvV3FX7IlQui1agSwyn9MDW/Gbl SDtXgsCtI+9CAT2HcXbLM6nM+T3/e1b/KaMXrscr/BAWJT3WgMaAp5VAFbtHDPbJM42z 0R5iULAT2p0GOQku++hCN9jnZ45rplUi4sjah0MdPJkbXTAeWiNNf3aoagELUsTiRAur bRxUOPR27oCKZHzmR2/9Mg7DP7+HYCptLUKoamKkxF+t+bwWQj9VEXqZNn7sgIlh2WM5 YnuYbjuVLER52t9lN4wpEVupZYfO4YqJbZW89unBGc+w4hvjhdkx8GQw75RQByDL1q6r fJgQ== X-Gm-Message-State: AA6/9RnKPWYQuJ8J/cew4HXoRqLvKtT0pi0EKekT79lJ38UrdcmWtz7qxpgf82p99h7NWQ== X-Received: by 10.25.212.206 with SMTP id l197mr12127710lfg.69.1476019808904; Sun, 09 Oct 2016 06:30:08 -0700 (PDT) Received: from obsidian (broadband-46-188-15-144.2com.net. [46.188.15.144]) by smtp.gmail.com with ESMTPSA id 69sm5130724lfq.39.2016.10.09.06.30.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 09 Oct 2016 06:30:08 -0700 (PDT) Date: Sun, 9 Oct 2016 16:30:06 +0300 From: Eugene Syromyatnikov To: strace-devel@lists.sourceforge.net Message-ID: <20161009133006.GA3129@obsidian> References: <20161005.192828.566127461630656590.yamato@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161005.192828.566127461630656590.yamato@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 09 Oct 2016 13:30:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 09 Oct 2016 13:30:11 +0000 (UTC) for IP:'209.85.215.67' DOMAIN:'mail-lf0-f67.google.com' HELO:'mail-lf0-f67.google.com' FROM:'evgsyr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.17 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.215.67 mail-lf0-f67.google.com 209.85.215.67 mail-lf0-f67.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 10 Oct 2016 04:29:54 -0400 Cc: dm-devel@redhat.com, mpatocka@redhat.com, yamato@redhat.com Subject: [dm-devel] [PATCH 08/21] dm: Use static constants for offset sizes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP This may improve readability an leads to more compact code. --- dm.c | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/dm.c b/dm.c index 66b615d..adfa97e 100644 --- a/dm.c +++ b/dm.c @@ -102,12 +102,14 @@ static void dm_decode_dm_target_spec(struct tcb *tcp, const struct dm_ioctl *ioc, const char *extra, uint32_t extra_size) { + static const uint32_t target_spec_size = + sizeof(struct dm_target_spec); uint32_t i; uint32_t offset = ioc->data_start; for (i = 0; i < ioc->target_count; i++) { - if (offset + (uint32_t) sizeof(struct dm_target_spec) >= offset && - offset + (uint32_t) sizeof(struct dm_target_spec) < extra_size) { + if (offset + target_spec_size >= offset && + offset + target_spec_size < extra_size) { uint32_t new_offset; const struct dm_target_spec *s = (const struct dm_target_spec *) (extra + offset); @@ -121,16 +123,14 @@ dm_decode_dm_target_spec(struct tcb *tcp, const struct dm_ioctl *ioc, QUOTE_0_TERMINATED); tprints(", string="); print_quoted_string((const char *) (s + 1), extra_size - - (offset + - sizeof(struct dm_target_spec)), + (offset + target_spec_size), QUOTE_0_TERMINATED); tprintf("}"); if (entering(tcp)) new_offset = offset + s->next; else new_offset = ioc->data_start + s->next; - if (new_offset <= offset + - (uint32_t) sizeof(struct dm_target_spec)) + if (new_offset <= offset + target_spec_size) goto misplaced; offset = new_offset; } else { @@ -145,13 +145,15 @@ static void dm_decode_dm_target_deps(const struct dm_ioctl *ioc, const char *extra, uint32_t extra_size) { + static const uint32_t target_deps_dev_offs = + offsetof(struct dm_target_deps, dev); uint32_t offset = ioc->data_start; - if (offset + (uint32_t) offsetof(struct dm_target_deps, dev) >= offset && - offset + (uint32_t) offsetof(struct dm_target_deps, dev) <= extra_size) { + if (offset + target_deps_dev_offs >= offset && + offset + target_deps_dev_offs <= extra_size) { uint32_t i; - uint32_t space = (extra_size - (offset + - offsetof(struct dm_target_deps, dev))) / sizeof(__u64); + uint32_t space = (extra_size - offset - target_deps_dev_offs) / + sizeof(__u64); const struct dm_target_deps *s = (const struct dm_target_deps *) (extra + offset); @@ -173,11 +175,13 @@ static void dm_decode_dm_name_list(const struct dm_ioctl *ioc, const char *extra, uint32_t extra_size) { + static const uint32_t name_list_name_offs = + offsetof(struct dm_name_list, name); uint32_t offset = ioc->data_start; while (1) { - if (offset + (uint32_t) offsetof(struct dm_name_list, name) >= offset && - offset + (uint32_t) offsetof(struct dm_name_list, name) < extra_size) { + if (offset + name_list_name_offs >= offset && + offset + name_list_name_offs < extra_size) { const struct dm_name_list *s = (const struct dm_name_list *) (extra + offset); @@ -186,13 +190,12 @@ dm_decode_dm_name_list(const struct dm_ioctl *ioc, const char *extra, tprintf(", {dev=makedev(%u, %u), name=", major(s->dev), minor(s->dev)); print_quoted_string(s->name, extra_size - (offset + - offsetof(struct dm_name_list, - name)), QUOTE_0_TERMINATED); + name_list_name_offs), + QUOTE_0_TERMINATED); tprints("}"); if (!s->next) break; - if (offset + s->next <= offset + - (uint32_t) offsetof(struct dm_name_list, name)) + if (offset + s->next <= offset + name_list_name_offs) goto misplaced; offset = offset + s->next; } else { @@ -207,26 +210,25 @@ static void dm_decode_dm_target_versions(const struct dm_ioctl *ioc, const char *extra, uint32_t extra_size) { + static const uint32_t target_vers_name_offs = + offsetof(struct dm_target_versions, name); uint32_t offset = ioc->data_start; while (1) { - if (offset + (uint32_t) offsetof(struct dm_target_versions, name) >= - offset && - offset + (uint32_t) offsetof(struct dm_target_versions, name) < - extra_size) { + if (offset + target_vers_name_offs >= offset && + offset + target_vers_name_offs < extra_size) { const struct dm_target_versions *s = (const struct dm_target_versions *)(extra + offset); tprints(", {name="); print_quoted_string(s->name, extra_size - (offset + - offsetof(struct dm_target_versions, - name)), QUOTE_0_TERMINATED); + target_vers_name_offs), + QUOTE_0_TERMINATED); tprintf(", version=%" PRIu32 ".%" PRIu32 ".%" PRIu32 "}", s->version[0], s->version[1], s->version[2]); if (!s->next) break; - if (offset + s->next <= offset + - (uint32_t) offsetof(struct dm_target_versions, name)) + if (offset + s->next <= offset + target_vers_name_offs) goto misplaced; offset = offset + s->next; } else { @@ -242,17 +244,19 @@ static void dm_decode_dm_target_msg(const struct dm_ioctl *ioc, const char *extra, uint32_t extra_size) { + static const uint32_t target_msg_message_offs = + offsetof(struct dm_target_msg, message); uint32_t offset = ioc->data_start; - if (offset + (uint32_t) offsetof(struct dm_target_msg, message) >= offset && - offset + (uint32_t) offsetof(struct dm_target_msg, message) < extra_size) { + if (offset + target_msg_message_offs >= offset && + offset + target_msg_message_offs < extra_size) { const struct dm_target_msg *s = (const struct dm_target_msg *) (extra + offset); tprintf(", {sector=%" PRIu64 ", message=", (uint64_t) s->sector); print_quoted_string(s->message, extra_size - - offsetof(struct dm_target_msg, message), + target_msg_message_offs, QUOTE_0_TERMINATED); tprints("}"); } else {