Skip to content

drivers/at: fix invalid function pointer cast.#9740

Merged
leandrolanzieri merged 1 commit intoRIOT-OS:masterfrom
jcarrano:at_driver-fix-cast
Nov 1, 2018
Merged

drivers/at: fix invalid function pointer cast.#9740
leandrolanzieri merged 1 commit intoRIOT-OS:masterfrom
jcarrano:at_driver-fix-cast

Conversation

@jcarrano
Copy link
Copy Markdown
Contributor

@jcarrano jcarrano commented Aug 8, 2018

Contribution description

Fix an invalid cast of a function pointer. ARM GCC 8.2.0 (on Arch linux) was (rightly) complaining about this.

As a note, I'd regard any explicit cast of function pointers suspicious. That's something that simply should not be done.

@jcarrano jcarrano added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers labels Aug 8, 2018
Copy link
Copy Markdown
Member

@A-Paul A-Paul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cladmi, thank you for your approach to fix this.

I have two remarks.
There are other places where the same cast is used:

paul@hedon:~/git/RIOT$ global --reference --cxref isrpipe_write_one
isrpipe_write_one   29 drivers/at/at.c      uart_init(uart, baudrate, (uart_rx_cb_t) isrpipe_write_one,
isrpipe_write_one  105 drivers/ethos/ethos.c             isrpipe_write_one(&uart_stdio_isrpipe, c);
isrpipe_write_one   65 sys/include/isrpipe.h int isrpipe_write_one(isrpipe_t *isrpipe, char c);
isrpipe_write_one   89 sys/uart_stdio/uart_stdio.c     uart_init(UART_STDIO_DEV, UART_STDIO_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);
isrpipe_write_one   91 sys/uart_stdio/uart_stdio.c     uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);

I think it might be better to change them all or none, instead of getting diversification.

Code size is increasing by 8 byte. I tried inline but gained 8 bytes too.

    1002              0      20    1022     3fe xtimer_core.o (ex /xtimer.a)
-   1012              0       0    1012     3f4 at.o (ex /at.a)
+   1020              0       0    1020     3fc at.o (ex /at.a)
     768              0       0     768     300 xtimer.o (ex /xtimer.a)

@jcarrano
Copy link
Copy Markdown
Contributor Author

There are other places where the same cast is used:

I'll take a look later. Is there a tool to find function pointer casts? As I mentioned before, most of the time a function cast is just wrong.

Code size is increasing by 8 byte. I tried inline but gained 8 bytes too.

It is to be expected. In fact, I'm quite surprised it is only 8 bytes. If the exact same cast is used everywhere it may make sense to share the wrapper, instead of having each module replicate it as a static function.

Btw, im not cladmi.

@A-Paul
Copy link
Copy Markdown
Member

A-Paul commented Aug 21, 2018

Hi @jcarrano

Btw, im not cladmi.

How did I messed this up? :D Sorry. I hope neither you or cladmi feel insulted by this mismatch. ;-)

I'll take a look later. Is there a tool to find function pointer casts?

There is a tool called global. In my previous comment is the output for all places where isrpipe_write_one is called or declared. You can see the mentioned casts are in the printed codelines.
Or, at least three of them.

@jcarrano
Copy link
Copy Markdown
Contributor Author

@A-Paul Are you still there? The AT driver is still not compiling, so this fix remains relevant.

Regarding other modules, I have to investigate why it does no fail compilation? Can we get this in first?

@jia200x
Copy link
Copy Markdown
Member

jia200x commented Oct 30, 2018

marked for the Release

@jia200x jia200x added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Oct 30, 2018
@jcarrano jcarrano added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 30, 2018
@jcarrano
Copy link
Copy Markdown
Contributor Author

@jia200x

marked for the Release

do you need me to do anything regarding this?

@jia200x
Copy link
Copy Markdown
Member

jia200x commented Oct 30, 2018

I think it might be better to change them all or none, instead of getting diversification.

Agreed. I would still try to get this one in otherwise the Release tests fail with GCC8, and change the rest in follow ups. Maybe open a tracker would be useful.

@jcarrano if we could get this in soon-ish would be nice! As said before, maybe a tracker would be nice. But for this Release 2018.10, IMO this should be there for giving more toolchain support.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Oct 30, 2018

@leandrolanzieri as you did a duplicate PR, can you review here ?

@leandrolanzieri
Copy link
Copy Markdown
Contributor

leandrolanzieri commented Oct 30, 2018

Sure. ACK for:

  • Fundamentals
  • Code design
  • Code style
  • Documentation

@jia200x will test this now.

@leandrolanzieri leandrolanzieri self-assigned this Oct 30, 2018
@leandrolanzieri leandrolanzieri added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Oct 30, 2018
@cladmi cladmi requested review from kaspar030 and vincent-d October 30, 2018 11:12
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Oct 30, 2018

I added people who wrote and maintain this module to review.

Copy link
Copy Markdown
Contributor Author

@jcarrano jcarrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-suggesting changes bc. I don't want to open up a real editor.

@jia200x
Copy link
Copy Markdown
Member

jia200x commented Oct 30, 2018

In current master:

Building application "tests_driver_at" for "native" with MCU "native".

"make" -C /home/jialamos/Development/RIOT/boards/native
"make" -C /home/jialamos/Development/RIOT/boards/native/drivers
"make" -C /home/jialamos/Development/RIOT/core
"make" -C /home/jialamos/Development/RIOT/cpu/native
"make" -C /home/jialamos/Development/RIOT/cpu/native/periph
"make" -C /home/jialamos/Development/RIOT/cpu/native/vfs
"make" -C /home/jialamos/Development/RIOT/drivers
"make" -C /home/jialamos/Development/RIOT/drivers/at
/home/jialamos/Development/RIOT/drivers/at/at.c: In function ‘at_dev_init’:
/home/jialamos/Development/RIOT/drivers/at/at.c:29:31: error: cast between incompatible function types from ‘int (*)(isrpipe_t *, char)’ {aka ‘int (*)(struct <anonymous> *, char)’} to ‘void (*)(void *, uint8_t)’ {aka ‘void (*)(void *, unsigned char)’} [-Werror=cast-function-type]
     uart_init(uart, baudrate, (uart_rx_cb_t) isrpipe_write_one,
                               ^
cc1: all warnings being treated as errors
make[3]: *** [/home/jialamos/Development/RIOT/Makefile.base:83: /home/jialamos/Development/RIOT/tests/driver_at/bin/native/at/at.o] Error 1
make[2]: *** [/home/jialamos/Development/RIOT/Makefile.base:20: ALL--/home/jialamos/Development/RIOT/drivers/at] Error 2
make[1]: *** [/home/jialamos/Development/RIOT/Makefile.base:20: ALL--/home/jialamos/Development/RIOT/drivers] Error 2
make: *** [/home/jialamos/Development/RIOT/tests/driver_at/../../Makefile.include:445: /home/jialamos/Development/RIOT/tests/driver_at/bin/native/application_tests_driver_at.a] Error 2


With PR:

"make" -C /home/jialamos/Development/RIOT/boards/native
"make" -C /home/jialamos/Development/RIOT/boards/native/drivers
"make" -C /home/jialamos/Development/RIOT/core
"make" -C /home/jialamos/Development/RIOT/cpu/native
"make" -C /home/jialamos/Development/RIOT/cpu/native/periph
"make" -C /home/jialamos/Development/RIOT/cpu/native/vfs
"make" -C /home/jialamos/Development/RIOT/drivers
"make" -C /home/jialamos/Development/RIOT/drivers/at
"make" -C /home/jialamos/Development/RIOT/drivers/periph_common
"make" -C /home/jialamos/Development/RIOT/sys
"make" -C /home/jialamos/Development/RIOT/sys/auto_init
"make" -C /home/jialamos/Development/RIOT/sys/div
"make" -C /home/jialamos/Development/RIOT/sys/fmt
"make" -C /home/jialamos/Development/RIOT/sys/isrpipe
"make" -C /home/jialamos/Development/RIOT/sys/shell
"make" -C /home/jialamos/Development/RIOT/sys/tsrb
"make" -C /home/jialamos/Development/RIOT/sys/xtimer
   text    data     bss     dec     hex filename
  44929     760   49404   95093   17375 /home/jialamos/Development/RIOT/tests/driver_at/bin/native/tests_driver_at.elf

So, tested!

@leandrolanzieri leandrolanzieri added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 30, 2018
@jia200x
Copy link
Copy Markdown
Member

jia200x commented Oct 30, 2018

@jcarrano please squash! ;)

@jcarrano
Copy link
Copy Markdown
Contributor Author

@jia200x Done.

@leandrolanzieri leandrolanzieri added Reviewed: 3-testing The PR was tested according to the maintainer guidelines CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 31, 2018
Copy link
Copy Markdown
Contributor

@leandrolanzieri leandrolanzieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed, tested and CI passing. So ACK.

@leandrolanzieri leandrolanzieri merged commit 8507131 into RIOT-OS:master Nov 1, 2018
@leandrolanzieri
Copy link
Copy Markdown
Contributor

@jcarrano can you please provide the backport against the 2018.10-branch?

@jcarrano
Copy link
Copy Markdown
Contributor Author

jcarrano commented Nov 1, 2018

@leandrolanzieri Done: #10309

@jia200x jia200x added this to the Release 2018.10 milestone Nov 1, 2018
@jcarrano jcarrano deleted the at_driver-fix-cast branch November 8, 2018 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants