Welcome! Log In Create A New Profile

Advanced

kernel development

Posted by feas 
kernel development
November 07, 2016 12:16AM
I have been playing around with git and editing kernel files with the ./scripts/checkpatch.pl command. While most of the proposed edits seem pretty straight forward, there have been enough that are not, and make me nervous that I may be changing the function of some of the programs.

For example:

ERROR: "foo * bar" should be "foo *bar"        INTERNAL_SIZE_T sz = n * elem_size;

To me this seems fine and I would think it is a false positive as it would seem to me this is simple multiplication to return a value.

ERROR: "foo* bar" should be "foo *bar"        size_t malloc_usable_size(Void_t* mem)

Here, the suggestion is different and I don't understand why '*' would be to one side or the other. I would say it's an example of what not to name a variable and take a ruler to whosoever hands! Or is it just a typo?


  assert (chunk_is_mmapped(p));
  assert(! ((char*)p >= sbrk_base && (char*)p < sbrk_base + sbrked_mem));
  assert((n_mmaps > 0));
  assert(((p->prev_size + size) & (malloc_getpagesize-1)) == 0);

  n_mmaps--;
  mmapped_mem -= (size + p->prev_size);

  ret = munmap((char *)p - p->prev_size, size + p->prev_size);

So here we are again with what is in my opinion a bad variable '(char*)' that later becomes '(char *)'. WTF!? Wheres my ruler?

Are there valid reasons for poor naming conventions such as foo* or *foo and such.
Back in the day when I was taught to write the programs we used to do our job we would have had bloody knuckles, sore ears and or a knot in the back of the head.

How do I make a determination and or better yet query the individual responsible or community to find out how to proceed?

I can't believe such errors would compile let alone run.

Don't get me wrong, I know this stuff isn't easy and fat fingers happen to us all but this just seems like screw it.

I have not written anything in a long time and much has changed but I am trying to learn the new stuff to try and give back to the community with what is basically style corrections till i get better, It just amazes me that stuff like this is in the source and there are tools in place to check for it.

On a side note does anyone know of anything training wise that may have a program with known errors you are to fix and then compare to a master?
Re: kernel development
November 07, 2016 01:04AM
feas,

> ERROR: "foo * bar" should be "foo *bar"
> ERROR: "foo* bar" should be "foo *bar"

This is the kernel coding standard. For example, "foo * bar" must be "foo *bar". Because if foo is a struct, then the 1st line would not make sense to be multiplication. The 2nd line is OK, but coding standard make the code easier to read for everybody.

> ret = munmap((char *)p - p->prev_size, size + p->prev_size);

This is C code. So (char *) is a correct coding style for a cast operation.

> How do I make a determination and or better yet
> query the individual responsible or community to
> find out how to proceed?
>

Kernel mailing list. That's the only relevant place that all types of questions should be posted.

> On a side note does anyone know of anything
> training wise that may have a program with known
> errors you are to fix and then compare to a
> master?

If the error is obvious then you just clone Linus master Git repo, and fix it. But when you submit, it should go to subsystem repo such as USB, network, ... If the error is not known where it was introduced, then Git bisect to track it down (bisect does a binary search to a commit, you build and test at each step).

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 11/07/2016 01:06AM by bodhi.
Re: kernel development
November 07, 2016 02:40AM
Thanks again.

Seems it will always be a chicken an egg thing. I think style guides are the way to avoid confusion but there will always be those who still want to do it their own way. https://accu.org/index.php/journals/1445
Re: kernel development
November 07, 2016 02:55AM
Those who do this should be slapped silly :))

char* x, y, z;   // why? because it could be a coding error

This is more acceptable:
char *x, *y, *z;

Below is the best style, imo. Because it left no doubt about the intention and easier to remove/change individual variable:
char* x;
char* y;
char* z;
or
char *x;
char *y;
char *z;

Disclaimer: I've written a C compiler in college, so I'm more picky about coding style :)

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 11/07/2016 02:58AM by bodhi.
Re: kernel development
November 07, 2016 03:41AM
I am with you.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: