Need help with understanding format in check_unwind.c
Hi Dan,
Can you please explain what is the notation of these table entries.
{ "pci_request_regions", ALLOC, 0, "$", &int_zero, &int_zero },
{ "pci_release_regions", RELEASE, 0, "$" },
{ "request_free_mem_region", ALLOC, -1, "$->start",
&valid_ptr_min_sval, &valid_ptr_max_sval },
{ "__request_region", ALLOC, 1, "$", &valid_ptr_min_sval,
&valid_ptr_max_sval },
{ "release_and_free_resource", RELEASE, 0, "$->start" },
{ "release_resource", RELEASE, 0, "$->start" },
{ "__release_region", RELEASE, 1, "$" },
{ "ioremap", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },
{ "of_iomap", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },
{ "ioremap_encrypted", ALLOC, -1, "$", &valid_ptr_min_sval,
&valid_ptr_max_sval },
{ "iounmap", RELEASE, 0, "$" },
{ "request_threaded_irq", ALLOC, 0, "$", &int_zero, &int_zero },
{ "request_irq", ALLOC, 0, "$", &int_zero, &int_zero },
{ "free_irq", RELEASE, 0, "$" },Please correct if any of this is incorrect:
1. Second param is clear:
ALLOC is to tell that it is an allocation function RELEASE is to tell that it is an release function.
2. Third param is the arguement number that we are interested in starting from 0.
2141 int request_threaded_irq(unsigned int irq, irq_handler_t handler,
2142 irq_handler_t thread_fn, unsigned long irqflags,
2143 const char *devname, void *dev_id)
We are interested in irq which is 0th param, so
{ "request_threaded_irq", ALLOC, 0, "$", &int_zero, &int_zero },
and if it is return value, then -1 ?
3. Fourth parameter:
Variable name: "$" it can be anything
Sometimes: like in:
{ "request_free_mem_region", ALLOC, -1, "$->start", &valid_ptr_min_sval, &valid_ptr_max_sval}
Why did we use $->start ?
That is because the caller(dmirror_allocate_chunk()) passes start which is a struct member?
Can you explain a bit more on this ?
4. For ALLOC 4th and 5th params are the range of values in the success path ?
Can you please explain filling up these values for one or two APIs ?
Thanks,
Harshit
You're exactly right for points 1 and 2.
Quoted 9 lines · Harshit Mogalapalli
3. Fourth parameter:
Variable name: "$" it can be anything
Sometimes: like in:
{ "
request_free_mem_region", ALLOC, -1, "$->start",&valid_ptr_min_sval,&valid_ptr_max_sval}
Quoted 7 lines
Why did we use $->start ?
That is because the caller(dmirror_allocate_chunk()) passes start which is a struct member?
Can you explain a bit more on this ?
To be honest, that's probably just a mistake. I don't know why I tracked "$->start" instead of just "$".
Quoted 4 lines
4. For ALLOC 4th and 5th params are the range of values in the success path ?
Can you please explain filling up these values for one or two APIs ?
So the issue there is that we're find missing frees. If the allocation doesn't succeed then there is no need to free.
Some functions always succeed:
{ "set_reloc_control", ALLOC, 0, "$"},
{ "unset_reloc_control", RELEASE, 0, "$"},Some return 0 on success.
{ "__class_register", ALLOC, 0, "$", &int_zero, &int_zero },Some return a valid pointer.
{ "alloc_workqueue", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },Smatch tries to split returns into useful information. This is the success path, this is the failure path etc.
In this check_unwind.c script when there is an allocation which might fall outside the range then we don't set the state to allocated. So if the function returns unknown then it's not an allocation. But say we listed the success range as &int_zero to &int_ten (just an example) and the return was 7 then that would fall entirely in the success range and it's treated as a success. return_implies_param_key_exact() vs return_implies_param_key().
regards,
dan carpenter
Quoted 15 lines · Dan Carpenter
You're exactly right for points 1 and 2.
Quoted 11 lines · Harshit Mogalapalli
3. Fourth parameter:
Variable name: "$" it can be anything
Sometimes: like in:
{ "
request_free_mem_region", ALLOC, -1, "$->start",&valid_ptr_min_sval,&valid_ptr_max_sval}Why did we use $->start ?
Quoted 9 lines
Quoted 5 lines
That is because the caller(dmirror_allocate_chunk()) passes start which is a struct member?
Can you explain a bit more on this ?
To be honest, that's probably just a mistake. I don't know why I tracked "$->start" instead of just "$".
Oh okay,
1926 struct resource *request_free_mem_region(struct resource *base,
1927 unsigned long size, const char *name)
1928 {
So this should be:
{ "request_free_mem_region", ALLOC, -1 , "$", &valid_ptr_min_sval, &valid_ptr_max_sval}
Can you explain a bit more on why are we interested in the return value instead of just saying we are interested in resource here on this :
and have third param as -1 instead of just 0(resource) ?
Quoted 15 lines
Quoted 5 lines
4. For ALLOC 4th and 5th params are the range of values in the success path ?
Can you please explain filling up these values for one or two APIs ?
So the issue there is that we're find missing frees. If the allocation doesn't succeed then there is no need to free.
Some functions always succeed:
{ "set_reloc_control", ALLOC, 0, "$"}, { "unset_reloc_control", RELEASE, 0, "$"},Some return 0 on success.
Quoted 9 lines
{ "__class_register", ALLOC, 0, "$", &int_zero, &int_zero },Some return a valid pointer.
{ "alloc_workqueue", ALLOC, -1, "$", &valid_ptr_min_sval, &valid_ptr_max_sval },Smatch tries to split returns into useful information. This is the success path, this is the failure path etc.
Thanks a lot for explaining this.
Regards,
Harshit
Quoted 10 lines
In this
check_unwind.cscript when there is an allocation which might fall outside the range then we don't set the state to allocated. So if the function returns unknown then it's not an allocation. But say we listed the success range as&int_zeroto&int_ten(just an example) and the return was 7 then that would fall entirely in the success range and it's treated as a success.return_implies_param_key_exact()vsreturn_implies_param_key().regards,
dan carpenter
Quoted 30 lines · Harshit Mogalapalli
Quoted 15 lines · Dan Carpenter
You're exactly right for points 1 and 2.
Quoted 11 lines · Harshit Mogalapalli
3. Fourth parameter:
Variable name: "$" it can be anything
Sometimes: like in:
{ "
request_free_mem_region", ALLOC, -1, "$->start",&valid_ptr_min_sval,&valid_ptr_max_sval}Why did we use $->start ?
Quoted 9 lines
Quoted 5 lines
That is because the caller(dmirror_allocate_chunk()) passes start which is a struct member?
Can you explain a bit more on this ?
To be honest, that's probably just a mistake. I don't know why I tracked "$->start" instead of just "$".
Oh okay,
1926 struct resource *request_free_mem_region(struct resource *base,
1927 unsigned long size, const char *name)
1928 {
Quoted 9 lines
So this should be:
{ "
request_free_mem_region", ALLOC, -1 , "$",&valid_ptr_min_sval,&valid_ptr_max_sval}Can you explain a bit more on why are we interested in the return value instead of just saying we are interested in resource here on this :
and have third param as -1 instead of just 0(resource) ?
I can't find a lot of examples of request_free_mem_region()... I guess I was looking at something like this:
Alloc:sound/aoa/soundbus/i2sbus/core.c
262 dev->allocated_resource[i] =
263 request_mem_region(dev->resources[i].start,
264 resource_size(&dev->resources[i]),
265 dev->rnames[i]);
sound/aoa/soundbus/i2sbus/core.c
81 release_and_free_resource(i2sdev->allocated_resource[i]);
It's freeing -1. That one is obvious.
Anyway, it's possible that I just got the others wrong...
regards,
dan carpenter