linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Gix <bgix@codeaurora.org>
To: Hendrik Sattler <post@hendrik-sattler.de>
Cc: Hemant Gupta <hemant.gupta@stericsson.com>,
	linux-bluetooth@vger.kernel.org,
	Naresh Gupta <naresh.gupta@stericsson.com>,
	Hemant Gupta <hemantgupta.ste@gmail.com>
Subject: Re: [RFC] mgmt: Add support for Passkey handling
Date: Mon, 05 Dec 2011 10:59:14 -0800	[thread overview]
Message-ID: <4EDD1482.3000306@codeaurora.org> (raw)
In-Reply-To: <b5e0b125ccef74762e3665620069daad@mail.hendrik-sattler.de>

Hi Hendrik,

On 12/5/2011 4:50 AM, Hendrik Sattler wrote:
> Am 05.12.2011 12:46, schrieb Hemant Gupta:
[...]
>> +static int mgmt_passkey_reply(int index, bdaddr_t *bdaddr, uint32_t
>> passkey)
>> +{
>> + char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_user_passkey_reply)];
>> + struct mgmt_hdr *hdr = (void *) buf;
>> + size_t buf_len;
>> + char addr[18];
>> +
>> + ba2str(bdaddr, addr);
>> + DBG("index %d addr %s passkey %06u", index, addr, passkey);
>> +
>> + memset(buf, 0, sizeof(buf));
>> +
>> + if (passkey == INVALID_PASSKEY) {
>> + struct mgmt_cp_user_passkey_neg_reply *cp;
>> +
>> + hdr->opcode = htobs(MGMT_OP_USER_PASSKEY_NEG_REPLY);
>> + hdr->len = htobs(sizeof(*cp));
>> + hdr->index = htobs(index);
>> +
>> + cp = (void *) &buf[sizeof(*hdr)];
>
> By definition, that the same as:
> cp = (void *) (hdr + 1);
> And you can do it in the same line as the definition of *cp.
>
>> + bacpy(&cp->bdaddr, bdaddr);
>> +
>> + buf_len = sizeof(*hdr) + sizeof(*cp);
>> + } else {
>> + struct mgmt_cp_user_passkey_reply *cp;
>> +
>> + hdr->opcode = htobs(MGMT_OP_USER_PASSKEY_REPLY);
>> + hdr->len = htobs(sizeof(*cp));
>> + hdr->index = htobs(index);
>> +
>> + cp = (void *) &buf[sizeof(*hdr)];
>> + bacpy(&cp->bdaddr, bdaddr);
>> + cp->passkey = htobl(passkey);
>> +
>> + buf_len = sizeof(*hdr) + sizeof(*cp);
>> + }
>
> Ever wondered why if and else look almost the same? They should be
> merged as far as possible.

I generally agree with this statement, but think it doesn't really apply 
here.  Since the definition of "cp" is different between the IF and the 
ELSE, the generated code is quite different, even though they look the 
same:  The sizeof(*cp) is different, the MGMT_OP Opcode is different, 
and the structure members might be named the same, but since they are in 
different structures, they are in fact different as well.

The only thing that could be safely "shared" is the hdr->index, I think.


-- 
Brian Gix
bgix@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

  reply	other threads:[~2011-12-05 18:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05 11:46 [RFC] mgmt: Add support for Passkey handling Hemant Gupta
2011-12-05 12:22 ` Andrei Emeltchenko
     [not found]   ` <CACj007=e6RLZEJyi4H28TPSjsZEQk_O7suU42U+z9_PeNezsjA@mail.gmail.com>
2011-12-05 16:26     ` Andrei Emeltchenko
2011-12-05 12:50 ` Hendrik Sattler
2011-12-05 18:59   ` Brian Gix [this message]
2011-12-06  7:43     ` Hemant GUPTA
     [not found]   ` <CACj007npMC+6EWOyNS24o1MvHBetjSXaiXc0HO0c_Z_dZgQADA@mail.gmail.com>
2011-12-06  7:58     ` Hendrik Sattler

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=4EDD1482.3000306@codeaurora.org \
    --to=bgix@codeaurora.org \
    --cc=hemant.gupta@stericsson.com \
    --cc=hemantgupta.ste@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=naresh.gupta@stericsson.com \
    --cc=post@hendrik-sattler.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).