Inline Macro issue
Saket Sinha
saket.sinha89 at gmail.com
Mon Jul 15 12:11:54 EDT 2013
BTW....I forgot to mention the problem got solved. Thanks to your
suggestions.
Regards,
Saket Sinha
On Mon, Jul 15, 2013 at 9:38 PM, Saket Sinha <saket.sinha89 at gmail.com>wrote:
> Russel:
> Thank you a curly bracket was missing. How could I not notice.
> Valdis:
> I shall take your suggestions.
> Mandeep:
> Thank you for that enlighting ideas
>
> Regards,
> Saket Sinha
>
>
>
> On Mon, Jul 15, 2013 at 7:52 PM, <Valdis.Kletnieks at vt.edu> wrote:
>
>> On Mon, 15 Jul 2013 17:39:15 +0530, Mandeep Sandhu said:
>>
>> > #define push_root() \
>> > recursive_mutex_lock(&context->id_lock); \
>> > context->uid = current->fsuid; \
>> > context->gid = current->fsgid; \
>> > do { \
>> > struct cred *new1 = prepare_creds(); \
>> > //make changes to any member of this structure \
>> > commit_creds(new1); \
>> > } while(0);
>>
>> Actually, this has 3 problems:
>>
>> 1) You have a call to mutex_loc() that doesn't get unlocked. This Is Bad.
>>
>> 2) If you're using the 'do { foo } while (0)' trick, you want to
>> put the *whole thing* inside the { } (Hint - you can put local variable
>> definitions inside the curlies as well).
>>
>> 3) Leave the ; off the 'while (0)' in the macro definition, because:
>>
>> > int main()
>> > {
>> > printf("in main\n");
>> > pushme
>> > return 0;
>> > }
>>
>> Somebody will forget and put a ; after pushme - and in some contexts, the
>> additional ; will then cause issues.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/75cfd758/attachment.html
More information about the Kernelnewbies
mailing list