Clarification on code section in qlge driver
Hi Julia,
I am trying to edit the above macro to incorporate an inline function as macros with control flows are highly discouraged. However, I wanted to inquire about some parameters in the FILL_SEG macro below so that I can be able effectively create a well parameterized function.
#42: FILE: drivers/staging/qlge/qlge_devlink.c:42:
+#define FILL_SEG(seg_hdr, seg_regs) \
+ do { \
+ err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs); \
+ if (err) { \
+ kvfree(dump); \
+ return err; \
+ } \+ } while (0)
The fmsg parameter and the dump parameter, both
in the qlge_fill_seg_() function inside the macro, where are they referenced from? Looking through the code, I cannot see global variables in relation to this. Are they command line arguments or does is thekernel set to provide them?
Any assistance will be appreciated.
Kind regards,
Dorcas
Quoted 6 lines · Dorcas Litunya
Hi Julia,
I am trying to edit the above macro to incorporate an inline function as macros with control flows are highly discouraged. However, I wanted to inquire about some parameters in the
FILL_SEGmacro below so that I can be able effectively create a well parameterized function.
seg_hdr and seg_regs are not vealues, they are field names. There is no way that you can pass a field name to a function. You could pass the complete values &dump->seg_hdr and dump->seg_regs, but then one could wonder why not pass dump as well. And then the calls would start getting a bit large.
Since this macro is specific to a particular function and is defined right before that function, I think it would be better to leave it as it is.
julia
Quoted 25 lines
#42: FILE:
drivers/staging/qlge/qlge_devlink.c:42:(quoted diff) +8
-0+#define FILL_SEG(seg_hdr, seg_regs) \ + do { \ + err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs); \ + if (err) { \ + kvfree(dump); \ + return err; \ + } \ + } while (0)The fmsg parameter and the dump parameter, both
in theqlge_fill_seg_()function inside the macro, where are they referenced from? Looking through the code, I cannot see global variables in relation to this. Are they command line arguments or does is thekernel set to provide them?Any assistance will be appreciated.
Kind regards,
Dorcas
Quoted 11 lines · Julia Lawall
Quoted 6 lines · Dorcas Litunya
Hi Julia,
I am trying to edit the above macro to incorporate an inline function as macros with control flows are highly discouraged. However, I wanted to inquire about some parameters in the
FILL_SEGmacro below so that I can be able effectively create a well parameterized function.
Quoted 9 lines
seg_hdrandseg_regsare not vealues, they are field names. There is no way that you can pass a field name to a function. You could pass the complete values&dump->seg_hdranddump->seg_regs, but then one could wonder why not pass dump as well. And then the calls would start getting a bit large.Since this macro is specific to a particular function and is defined right before that function, I think it would be better to leave it as it is.
Makes a lot of sense. My other idea besides defining the entire macro as a function was to encapsulate what the macro does in the code block as a function as below:
#define FILL_SEG(seg_hdr, seg_regs,fmsg,dump) fill_seg_handling_error(fmsg,dump)
static int fill_seg_handling_error(struct fmsg *fmsg, struct dump *dump) {
int err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs);
if (err) {
kvfree(dump);
return err;
}
return 0
}Not sure if doing it this way creates some sort of redudancy or may lead to some unprecedented problems or can it be considered
as a way to make the code more readable and maintainable?
Dorcas
Quoted 35 lines
julia
Quoted 25 lines
#42: FILE:
drivers/staging/qlge/qlge_devlink.c:42:(quoted diff) +8
-0+#define FILL_SEG(seg_hdr, seg_regs) \ + do { \ + err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs); \ + if (err) { \ + kvfree(dump); \ + return err; \ + } \ + } while (0)The fmsg parameter and the dump parameter, both
in theqlge_fill_seg_()function inside the macro, where are they referenced from? Looking through the code, I cannot see global variables in relation to this. Are they command line arguments or does is thekernel set to provide them?Any assistance will be appreciated.
Kind regards,
Dorcas
Quoted 36 lines · Dorcas Litunya
Quoted 11 lines · Julia Lawall
Quoted 6 lines · Dorcas Litunya
Hi Julia,
I am trying to edit the above macro to incorporate an inline function as macros with control flows are highly discouraged. However, I wanted to inquire about some parameters in the
FILL_SEGmacro below so that I can be able effectively create a well parameterized function.Quoted 9 lines
seg_hdrandseg_regsare not vealues, they are field names. There is no way that you can pass a field name to a function. You could pass the complete values&dump->seg_hdranddump->seg_regs, but then one could wonder why not pass dump as well. And then the calls would start getting a bit large.Since this macro is specific to a particular function and is defined right before that function, I think it would be better to leave it as it is.
Makes a lot of sense. My other idea besides defining the entire macro as a function was to encapsulate what the macro does in the code block as a function as below:
#define
FILL_SEG(seg_hdr, seg_regs,fmsg,dump)fill_seg_handling_error(fmsg,dump)static int fill_seg_handling_error(struct fmsg *fmsg, struct dump *dump) { int err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs); if (err) { kvfree(dump); return err; } return 0 }
Quoted 3 lines
Not sure if doing it this way creates some sort of redudancy or may lead to some unprecedented problems or can it be considered
as a way to make the code more readable and maintainable?
Sorry to hqave missed this mail. I think that the goal of the original macro was to jump directly out of the function on failure, not to have the code cluttered with tests, so this change would not give the full benefit.
julia
Quoted 38 lines
Dorcas
Quoted 35 lines
julia
Quoted 25 lines
#42: FILE:
drivers/staging/qlge/qlge_devlink.c:42:(quoted diff) +8
-0+#define FILL_SEG(seg_hdr, seg_regs) \ + do { \ + err = qlge_fill_seg_(fmsg, &dump->seg_hdr, dump->seg_regs); \ + if (err) { \ + kvfree(dump); \ + return err; \ + } \ + } while (0)The fmsg parameter and the dump parameter, both
in theqlge_fill_seg_()function inside the macro, where are they referenced from? Looking through the code, I cannot see global variables in relation to this. Are they command line arguments or does is thekernel set to provide them?Any assistance will be appreciated.
Kind regards,
Dorcas