All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v2] mailbox: fix invalid use of sizeof in mailbox_msg_send()
@ 2013-03-23  7:04 Wei Yongjun
  2013-03-26  2:07 ` Anna, Suman
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2013-03-23  7:04 UTC (permalink / raw)
  To: s-anna, linus.walleij, loic.pallardy, omar.ramirez, lugo.fernando
  Cc: yongjun_wei, linux-kernel

From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

sizeof() when applied to a pointer typed expression gives the
size of the pointer, not that of the pointed data.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/mailbox/mailbox.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 5fea5c2..78e52c0 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -83,7 +83,7 @@ int mailbox_msg_send(struct mailbox *mbox, struct mailbox_msg *msg)
 
 	mutex_lock(&mq->mlock);
 
-	if (kfifo_avail(&mq->fifo) < (sizeof(msg) + msg->size)) {
+	if (kfifo_avail(&mq->fifo) < (sizeof(*msg) + msg->size)) {
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -93,8 +93,8 @@ int mailbox_msg_send(struct mailbox *mbox, struct mailbox_msg *msg)
 		goto out;
 	}
 
-	len = kfifo_in(&mq->fifo, (unsigned char *)msg, sizeof(msg));
-	WARN_ON(len != sizeof(msg));
+	len = kfifo_in(&mq->fifo, (unsigned char *)msg, sizeof(*msg));
+	WARN_ON(len != sizeof(*msg));
 
 	if (msg->size && msg->pdata) {
 		len = kfifo_in(&mq->fifo, (unsigned char *)msg->pdata,



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH -next v2] mailbox: fix invalid use of sizeof in mailbox_msg_send()
  2013-03-23  7:04 [PATCH -next v2] mailbox: fix invalid use of sizeof in mailbox_msg_send() Wei Yongjun
@ 2013-03-26  2:07 ` Anna, Suman
  0 siblings, 0 replies; 2+ messages in thread
From: Anna, Suman @ 2013-03-26  2:07 UTC (permalink / raw)
  To: Wei Yongjun, linus.walleij, loic.pallardy, omar.ramirez, lugo.fernando
  Cc: yongjun_wei, linux-kernel

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> sizeof() when applied to a pointer typed expression gives the size of the pointer,
> not that of the pointed data.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  drivers/mailbox/mailbox.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index
> 5fea5c2..78e52c0 100644
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c
> @@ -83,7 +83,7 @@ int mailbox_msg_send(struct mailbox *mbox, struct
> mailbox_msg *msg)
> 
>  	mutex_lock(&mq->mlock);
> 
> -	if (kfifo_avail(&mq->fifo) < (sizeof(msg) + msg->size)) {
> +	if (kfifo_avail(&mq->fifo) < (sizeof(*msg) + msg->size)) {
>  		ret = -ENOMEM;
>  		goto out;
>  	}
> @@ -93,8 +93,8 @@ int mailbox_msg_send(struct mailbox *mbox, struct
> mailbox_msg *msg)
>  		goto out;
>  	}
> 
> -	len = kfifo_in(&mq->fifo, (unsigned char *)msg, sizeof(msg));
> -	WARN_ON(len != sizeof(msg));
> +	len = kfifo_in(&mq->fifo, (unsigned char *)msg, sizeof(*msg));
> +	WARN_ON(len != sizeof(*msg));
> 
>  	if (msg->size && msg->pdata) {
>  		len = kfifo_in(&mq->fifo, (unsigned char *)msg->pdata,
>

Looks good, thanks. I have added this patch to my branch on github.

Regards
Suman
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-26  2:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-23  7:04 [PATCH -next v2] mailbox: fix invalid use of sizeof in mailbox_msg_send() Wei Yongjun
2013-03-26  2:07 ` Anna, Suman

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.