All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: "Hefty, Sean" <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>,
	"linux-rdma
	(linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org)"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Ira Weiny (weiny2-i2BcT+NCU+M@public.gmane.org)"
	<weiny2-i2BcT+NCU+M@public.gmane.org>
Subject: Re: [PATCH] ib-diags: Add cast to fix build on windows
Date: Thu, 22 Sep 2011 15:27:56 -0600	[thread overview]
Message-ID: <20110922212756.GJ28454@obsidianresearch.com> (raw)
In-Reply-To: <1828884A29C6694DAF28B7E6B8A8237316E67532-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>

On Thu, Sep 22, 2011 at 08:20:54PM +0000, Hefty, Sean wrote:
 
> The entire windows tree is built using the WinDDK compiler.  I
> haven't found a way to disable that warning that works.  Since the
> warning is real, an explicit cast at least lets someone reading the
> code know that the author took truncation into account.

It would be much better to fix this at the source.

 mad_get_field16(..,IB_NODE_DEVID_F)

Then at least there is the option of doing a static or runtime check
that IB_NODE_DEVID_F is actually referring to a 16 bit field.

For instance, a static check might be possible with some compilers by
doing:

enum MAD_FIELDS8
{
IB_PORT_LOCAL_PORT_F
};

enum MAD_FIELDS16
{
IB_NODE_DEVID_F
};

uint8_t mad_get_field8(void *buf, int base_offs,
	               enum MAD_FIELDS8 field);
uint16_t mad_get_field16(void *buf, int base_offs,
	                 enum MAD_FIELDS16 field);

A compiler can produce a warning about mismatching enums.

Someone can fixup the enums later, but I'd much rather see you add a
patch with this hunk:

static inline uint16_t mad_get_field16(void *buf, int base_offs,
	                               enum MAD_FIELDS field)
{
   return (uint16_t)mad_get_field(buf,base_offs,field);
}

And another patch replacing every (uint16_t)mad_get_field with
mad_get_field16

Adding a cast is just pointless noise, doesn't fix or prove anything.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2011-09-22 21:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 18:29 [PATCH] ib-diags: Add cast to fix build on windows Hefty, Sean
     [not found] ` <1828884A29C6694DAF28B7E6B8A8237316E674F0-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-09-22 18:36   ` Bart Van Assche
     [not found]     ` <CAO+b5-qaSWm4RbhJ4Sk85Kysp2pJYOq6GmYJ=2oJhnL_Q7sa7g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-22 18:40       ` Hal Rosenstock
2011-09-22 20:20       ` Hefty, Sean
     [not found]         ` <1828884A29C6694DAF28B7E6B8A8237316E67532-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-09-22 21:27           ` Jason Gunthorpe [this message]
     [not found]             ` <20110922212756.GJ28454-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-09-22 21:33               ` Hefty, Sean
     [not found]                 ` <1828884A29C6694DAF28B7E6B8A8237316E675B2-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-09-22 21:39                   ` Jason Gunthorpe
     [not found]                     ` <20110922213907.GK28454-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-09-22 23:03                       ` Hefty, Sean
     [not found]                         ` <1828884A29C6694DAF28B7E6B8A8237316E675EB-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-09-22 23:32                           ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110922212756.GJ28454@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=bvanassche-HInyCGIudOg@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=weiny2-i2BcT+NCU+M@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.