mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Nicholas Krause <xerofoify@gmail.com>
Cc: gregkh@linuxfoundation.org, john.stultz@linaro.org,
	paul.gortmaker@windriver.com, gang.chen.5i5j@gmail.com,
	yongjun_wei@trendmicro.com.cn, dan.carpenter@oracle.com,
	tomas.winkler@intel.com, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: Change kzalloc to kcalloc
Date: Thu, 24 Jul 2014 10:47:25 -0400	[thread overview]
Message-ID: <20140724144725.GA32669@home.goodmis.org> (raw)
In-Reply-To: <1406156581-6052-1-git-send-email-xerofoify@gmail.com>

On Wed, Jul 23, 2014 at 07:03:01PM -0400, Nicholas Krause wrote:
> This changes the call to kzalloc to kcalloc in ion_dummy_driver
> for allocating the heap.
> 
> Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
> ---
>  drivers/staging/android/ion/ion_dummy_driver.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c
> index 3a45e79..8883432 100644
> --- a/drivers/staging/android/ion/ion_dummy_driver.c
> +++ b/drivers/staging/android/ion/ion_dummy_driver.c
> @@ -67,9 +67,8 @@ static int __init ion_dummy_init(void)
>  {
>  	int i, err;
>  
> 	idev = ion_device_create(NULL);
> -	heaps = kzalloc(sizeof(struct ion_heap *) * dummy_ion_pdata.nr,
> -			GFP_KERNEL);
> +	heaps = kcalloc(*dummy_ion_pdata.nr , sizeof((struct ion_heap *) *dummy_ion_pdata.nr) , GFP_KERNEL);
>  	if (!heaps)
>  		return -ENOMEM;
>  

Hi Nick,

Look, I know you are really enthusiastic, and want to help out. I get it.
But this patch is proof that you are not yet ready to work on a complex
project such as the Linux kernel. Maybe you want to try something
a bit easier. Like, say, systemd?

First of all, there was really nothing wrong with this code in the first
place. It is fine to use kzalloc. But lets just say you want to convert
it to kcalloc. The proper answer would have been:

	heaps = kcalloc(dummy_ion_pdata.nr, sizeof(struct ion_heap *), GFP_KERNEL);

That's rather simple. Just look at the prototype of kcalloc():

void *kcalloc(size_t n, size_t size, gfp_t flags)

The three parameters are the number of elements, the size of each individual
element, and then finally the flags used on how to allocate that memory.
I have to say, you did get the flags part correct.

Now lets look at what you did. For the size you had:

  *dummy_ion_ptr.nr

Do you have any idea of what that is? You just dereferenced the count.
That is, you didn't use the count, but you used the memory that is at
some location from address 0 + dummy_ion_ptr.nr. Now this probably wont
compile. At least not on 64 bit boxes as that nr field is only 32 bits
and a pointer would need to be 64 bits. It could possibly compile on
32 bit boxes, but it would definitely give you a warning about that.

Now lets look at the second parameter you used.

  sizeof((struct ion_heap *) *dummy_ion_pdata.nr)

This one takes a bit of thinking about. I'm actually confused at what
you were even trying to do. What the compiler would try to do is to
break it up. First you again dereference the dummy_ion_pdata.nr with

   *dummy_ion_pdata.nr

And then you convert the answer to that into the type "struct ion_heap *"

   (struct ion_heap *) *dummy_ion_pdata.nr

Finally, you take the sizeof of that answer. As you converted the type
into "struct ion_heap *", I think it would give you the size of that
pointer, that is, if it would compile in the first place.

Congrats! that is actually what we want the second parameter to be!
Although I doubt that you meant to do it that way. No one would mean
to do it that way unless they had no idea of what they were doing.


Basically what this patch tells me is that you do not have enough basic
knowledge of the C language to be programming in the kernel. Maybe you
want to be a BIOS programmer?

My advice to you is to find another project (Gnome?) and work with them
until you have a strong concept of C coding and then, and only then,
come back to working on the kernel. Kernel development is no place for
novice programmers. Sorry, but that's true. It will only give you a
bad reputation, and nasty comments from the real kernel developers.

Cheers!

-- Steve


  parent reply	other threads:[~2014-07-24 14:47 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 23:03 Nicholas Krause
2014-07-23 23:07 ` David Rientjes
2014-07-23 23:08 ` Richard Weinberger
2014-07-24 14:47 ` Steven Rostedt [this message]
2014-07-24 14:51   ` Steven Rostedt
2014-07-24 16:15     ` Måns Rullgård
2014-07-24 16:31       ` Nick Krause
2014-07-24 16:34         ` Måns Rullgård
2014-07-24 16:35           ` Nick Krause
2014-07-24 16:47             ` Måns Rullgård
2014-07-24 16:50               ` Nick Krause
2014-07-24 17:18                 ` Steven Rostedt
2014-07-24 17:30                   ` Harvey Harrison
2014-07-24 17:48                     ` Steven Rostedt
2014-07-24 18:41                       ` Nick Krause
2014-07-24 18:49                         ` Richard Weinberger
2014-07-24 18:55                           ` Nick Krause
2014-07-24 19:05                             ` Nick Krause
2014-07-24 19:11                               ` Richard Weinberger
2014-07-25  2:15                                 ` Chen Gang
2014-07-25  2:20                                   ` Nick Krause
2014-07-25  2:47                                     ` Chen Gang
2014-07-25  2:53                                       ` Nick Krause
2014-07-25  3:09                                         ` Chen Gang
2014-07-25  3:13                                           ` Nick Krause
2014-07-25  3:21                                             ` Chen Gang
2014-07-25  3:30                                               ` Nick Krause
2014-07-25  3:34                                                 ` Chen Gang
2014-07-25  3:39                                                   ` Nick Krause
2014-07-25  4:33                                                     ` Chen Gang

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=20140724144725.GA32669@home.goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gang.chen.5i5j@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=tomas.winkler@intel.com \
    --cc=xerofoify@gmail.com \
    --cc=yongjun_wei@trendmicro.com.cn \
    /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

Powered by JetHome