diff mbox

MMC: Fix use of uninitialized data in mmc_cmd_app.

Message ID 1302726792-4733-1-git-send-email-andreiw@motorola.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrei Warkentin April 13, 2011, 8:33 p.m. UTC
mmc_cmd_app did not zero out mmc_command on stack.

Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
---
 drivers/mmc/core/sd_ops.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Chris Ball April 13, 2011, 8:24 p.m. UTC | #1
Hi Andrei,

On Wed, Apr 13 2011, Andrei Warkentin wrote:
> mmc_cmd_app did not zero out mmc_command on stack.
>
> Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
> ---
>  drivers/mmc/core/sd_ops.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
> index 76af349..71fdb07 100644
> --- a/drivers/mmc/core/sd_ops.c
> +++ b/drivers/mmc/core/sd_ops.c
> @@ -29,6 +29,8 @@ static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
>  	BUG_ON(!host);
>  	BUG_ON(card && (card->host != host));
>  
> +	memset(&cmd, 0, sizeof(struct mmc_command));
> +
>  	cmd.opcode = MMC_APP_CMD;
>  
>  	if (card) {

Thanks, pushed to mmc-next for .40.  I found a few more which I'm about
to post.

- Chris.
John Calixto April 13, 2011, 9:04 p.m. UTC | #2
On Wed, 13 Apr 2011, Andrei Warkentin wrote:

> mmc_cmd_app did not zero out mmc_command on stack.
> 
> Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
> ---
>  drivers/mmc/core/sd_ops.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
> index 76af349..71fdb07 100644
> --- a/drivers/mmc/core/sd_ops.c
> +++ b/drivers/mmc/core/sd_ops.c
> @@ -29,6 +29,8 @@ static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
>  	BUG_ON(!host);
>  	BUG_ON(card && (card->host != host));
>  
> +	memset(&cmd, 0, sizeof(struct mmc_command));
> +
>  	cmd.opcode = MMC_APP_CMD;
>  
>  	if (card) {
> -- 

Out of curiosity, why is:

	memset(&cmd, 0, sizeof(struct mmc_command));

preferred over:

	struct mmc_command cmd = {0};


John
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chris Ball April 13, 2011, 9:40 p.m. UTC | #3
Hi,

On Wed, Apr 13 2011, John Calixto wrote:
> Out of curiosity, why is:
>
> 	memset(&cmd, 0, sizeof(struct mmc_command));
>
> preferred over:
>
> 	struct mmc_command cmd = {0};

Thanks for the question.  I asked around, the verdict seems to be that
it *isn't* preferred, that the compiler can actually (theoretically)
do better with the zero initializer, and the memsets are probably
just holdover from when dynamic initialization of aggregates wasn't
available in C.

An even stronger benefit of the zero initializer is, of course, that
you can do a single-line grep to find out whether someone forgot to
initialize any of them.  (And it's a line shorter, too.)

So, now I'm thinking about a patch to convert all of our uses of
memset(.., 0, struct ..) over to { 0 } initializers.  Yell if
anyone has strong opinions.

Thanks,

- Chris.
diff mbox

Patch

diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 76af349..71fdb07 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -29,6 +29,8 @@  static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 	BUG_ON(!host);
 	BUG_ON(card && (card->host != host));
 
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
 	cmd.opcode = MMC_APP_CMD;
 
 	if (card) {