Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33238
Change subject: device: Tidy up add_more_links() ......................................................................
device: Tidy up add_more_links()
- Add documentation comment - Use 'unsigned int' to make checkpatch happy - Return early if no more links need to be added - Add error handling if malloc fails - Whitespace cleanups
Change-Id: I70976ee2539b058721d0ae3c15edf279253cd9b7 Signed-off-by: Jacob Garber jgarber1@ualberta.ca Found-by: Coverity CID 1229634 --- M src/device/device_util.c M src/include/device/device.h 2 files changed, 17 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/33238/1
diff --git a/src/device/device_util.c b/src/device/device_util.c index e2370a1..11954a1 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -654,7 +654,13 @@ return 0; }
-void add_more_links(struct device *dev, unsigned total_links) +/** + * Ensure the device has a minimum number of bus links. + * + * @param dev The device to add links to. + * @param total_links The minimum number of links to have. + */ +void add_more_links(struct device *dev, unsigned int total_links) { struct bus *link, *last = NULL; int link_num = -1; @@ -668,15 +674,20 @@ if (last) { int links = total_links - (link_num + 1); if (links > 0) { - link = malloc(links*sizeof(*link)); + link = malloc(links * sizeof(*link)); if (!link) die("Couldn't allocate more links!\n"); - memset(link, 0, links*sizeof(*link)); + memset(link, 0, links * sizeof(*link)); last->next = link; + } else { + /* No more links to add */ + return; } } else { - link = malloc(total_links*sizeof(*link)); - memset(link, 0, total_links*sizeof(*link)); + link = malloc(total_links * sizeof(*link)); + if (!link) + die("Couldn't allocate more links!\n"); + memset(link, 0, total_links * sizeof(*link)); dev->link_list = link; }
diff --git a/src/include/device/device.h b/src/include/device/device.h index 52635e1..8e9454c 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -191,7 +191,7 @@ void dev_set_enabled(struct device *dev, int enable); void disable_children(struct bus *bus); bool dev_is_active_bridge(struct device *dev); -void add_more_links(struct device *dev, unsigned total_links); +void add_more_links(struct device *dev, unsigned int total_links);
/* Option ROM helper functions */ void run_bios(struct device *dev, unsigned long addr);
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33238 )
Change subject: device: Tidy up add_more_links() ......................................................................
Patch Set 1: Code-Review+1
(1 comment)
https://review.coreboot.org/#/c/33238/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/33238/1//COMMIT_MSG@13 PS1, Line 13: - Whitespace cleanups Clean up whitespace
Hello Kyösti Mälkki, Paul Menzel, David Hendricks, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/33238
to look at the new patch set (#2).
Change subject: device: Tidy up add_more_links() ......................................................................
device: Tidy up add_more_links()
- Add documentation comment - Use 'unsigned int' to make checkpatch happy - Return early if no more links need to be added - Add error handling if malloc fails - Clean up whitespace
Change-Id: I70976ee2539b058721d0ae3c15edf279253cd9b7 Signed-off-by: Jacob Garber jgarber1@ualberta.ca Found-by: Coverity CID 1229634 --- M src/device/device_util.c M src/include/device/device.h 2 files changed, 17 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/33238/2
Jacob Garber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33238 )
Change subject: device: Tidy up add_more_links() ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/#/c/33238/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/33238/1//COMMIT_MSG@13 PS1, Line 13: - Whitespace cleanups
Clean up whitespace
Done
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33238 )
Change subject: device: Tidy up add_more_links() ......................................................................
Patch Set 2: Code-Review+1
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33238 )
Change subject: device: Tidy up add_more_links() ......................................................................
Patch Set 2: Code-Review+2
Martin Roth has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/33238 )
Change subject: device: Tidy up add_more_links() ......................................................................
device: Tidy up add_more_links()
- Add documentation comment - Use 'unsigned int' to make checkpatch happy - Return early if no more links need to be added - Add error handling if malloc fails - Clean up whitespace
Change-Id: I70976ee2539b058721d0ae3c15edf279253cd9b7 Signed-off-by: Jacob Garber jgarber1@ualberta.ca Found-by: Coverity CID 1229634 Reviewed-on: https://review.coreboot.org/c/coreboot/+/33238 Reviewed-by: Angel Pons th3fanbus@gmail.com Reviewed-by: Paul Menzel paulepanter@users.sourceforge.net Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/device/device_util.c M src/include/device/device.h 2 files changed, 17 insertions(+), 6 deletions(-)
Approvals: build bot (Jenkins): Verified Paul Menzel: Looks good to me, but someone else must approve Angel Pons: Looks good to me, approved
diff --git a/src/device/device_util.c b/src/device/device_util.c index e2370a1..11954a1 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -654,7 +654,13 @@ return 0; }
-void add_more_links(struct device *dev, unsigned total_links) +/** + * Ensure the device has a minimum number of bus links. + * + * @param dev The device to add links to. + * @param total_links The minimum number of links to have. + */ +void add_more_links(struct device *dev, unsigned int total_links) { struct bus *link, *last = NULL; int link_num = -1; @@ -668,15 +674,20 @@ if (last) { int links = total_links - (link_num + 1); if (links > 0) { - link = malloc(links*sizeof(*link)); + link = malloc(links * sizeof(*link)); if (!link) die("Couldn't allocate more links!\n"); - memset(link, 0, links*sizeof(*link)); + memset(link, 0, links * sizeof(*link)); last->next = link; + } else { + /* No more links to add */ + return; } } else { - link = malloc(total_links*sizeof(*link)); - memset(link, 0, total_links*sizeof(*link)); + link = malloc(total_links * sizeof(*link)); + if (!link) + die("Couldn't allocate more links!\n"); + memset(link, 0, total_links * sizeof(*link)); dev->link_list = link; }
diff --git a/src/include/device/device.h b/src/include/device/device.h index 52635e1..8e9454c 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -191,7 +191,7 @@ void dev_set_enabled(struct device *dev, int enable); void disable_children(struct bus *bus); bool dev_is_active_bridge(struct device *dev); -void add_more_links(struct device *dev, unsigned total_links); +void add_more_links(struct device *dev, unsigned int total_links);
/* Option ROM helper functions */ void run_bios(struct device *dev, unsigned long addr);