Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/52773 )
Change subject: pickit2_spi.c: Separate shutdown from failed init cleanup
......................................................................
pickit2_spi.c: Separate shutdown from failed init cleanup
Shutdown function was covering two different jobs here: 1) the actual
shutdown which is run at the end of the driver's lifecycle and
2) cleanup in cases when initialisation failed. Now, shutdown is only
doing its main job (#1), and the driver itself is doing cleanup
when init fails (#2).
The good thing is that now resources are released/closed immediately
in cases when init fails (vs shutdown function which was run at some
point later), and the driver leaves clean space after itself if init
fails.
And very importantly this unlocks API change which plans to move
register_shutdown inside register master API, see
https://review.coreboot.org/c/flashrom/+/51761
TEST=builds
BUG=b:185191942
Change-Id: I1b672b33169a7a1b6ceab190ad3f48c2f35c3a1f
Signed-off-by: Anastasia Klimchuk <aklm(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52773
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
Reviewed-by: Angel Pons <th3fanbus(a)gmail.com>
---
M pickit2_spi.c
1 file changed, 13 insertions(+), 14 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
Angel Pons: Looks good to me, approved
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 0bc17af..367d0fc 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -458,34 +458,33 @@
return 1;
}
- if (register_shutdown(pickit2_shutdown, NULL) != 0) {
- return 1;
- }
-
- if (pickit2_get_firmware_version()) {
- return 1;
- }
+ if (pickit2_get_firmware_version())
+ goto init_err_cleanup_exit;
/* Command Set SPI Speed */
- if (pickit2_set_spi_speed(spispeed_idx)) {
- return 1;
- }
+ if (pickit2_set_spi_speed(spispeed_idx))
+ goto init_err_cleanup_exit;
/* Command Set SPI Voltage */
msg_pdbg("Setting voltage to %i mV.\n", millivolt);
- if (pickit2_set_spi_voltage(millivolt) != 0) {
- return 1;
- }
+ if (pickit2_set_spi_voltage(millivolt) != 0)
+ goto init_err_cleanup_exit;
/* Perform basic setup.
* Configure pin directions and logic levels, turn Vdd on, turn busy LED on and clear buffers. */
int transferred;
if (libusb_interrupt_transfer(pickit2_handle, ENDPOINT_OUT, buf, CMD_LENGTH, &transferred, DFLT_TIMEOUT) != 0) {
msg_perr("Command Setup failed!\n");
- return 1;
+ goto init_err_cleanup_exit;
}
+ if (register_shutdown(pickit2_shutdown, NULL))
+ goto init_err_cleanup_exit;
register_spi_master(&spi_master_pickit2);
return 0;
+
+init_err_cleanup_exit:
+ pickit2_shutdown(NULL);
+ return 1;
}
--
To view, visit https://review.coreboot.org/c/flashrom/+/52773
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I1b672b33169a7a1b6ceab190ad3f48c2f35c3a1f
Gerrit-Change-Number: 52773
Gerrit-PatchSet: 2
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-MessageType: merged
Attention is currently required from: Nico Huber, Edward O'Callaghan.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/54066 )
Change subject: programmer: Smoothen register_spi_master() API
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS1:
> Thanks! Yes, let's add data pointer early. […]
Just went through my patches once again, there are three which have +2s, everyone had a look, and no comments - probably could be submitted?
CB:52773
CB:52774
CB:54044
If you submit them (unless you have comments of course!), those files will go into CB:54067. That would be really really nice!
--
To view, visit https://review.coreboot.org/c/flashrom/+/54066
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f
Gerrit-Change-Number: 54066
Gerrit-PatchSet: 2
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Wed, 12 May 2021 23:12:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Edward O'Callaghan, Angel Pons, Anastasia Klimchuk.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/54042 )
Change subject: stlinkv3_spi.c: Refactor singleton states into reentrant pattern
......................................................................
Patch Set 1:
(1 comment)
File stlinkv3_spi.c:
https://review.coreboot.org/c/flashrom/+/54042/comment/aadf8a9f_251ffb76
PS1, Line 533: stlinkv3_spi_open(sck_freq_kHz, stlinkv3_handle
> >>> Before this commit, the handle was closed unless register_shutdown() failed. […]
It's just the one more `goto err_exit` that you added (in case calloc
fails). It's one more case where resources are left open than before.
It's tiny compared to the other flaws around. So don't worry too much
about it.
I just realized there's even a double-libusb_exit() in case register_
spi_master() fails... and a new double-free() in this patch. So yes,
I think it's probably best to fix the error paths first. This change
would be easier to review if the code was sane already. I can also
fix things, it's more my fault that the code looks like this ;)
--
To view, visit https://review.coreboot.org/c/flashrom/+/54042
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id044661b864b506028720ea809bc524f0640469f
Gerrit-Change-Number: 54042
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Comment-Date: Wed, 12 May 2021 23:01:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Nico Huber, Edward O'Callaghan.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/54066 )
Change subject: programmer: Smoothen register_spi_master() API
......................................................................
Patch Set 1:
(2 comments)
Patchset:
PS1:
> I know about CB:51761. It is focused on the shutdown pointer, though. I still […]
Thanks! Yes, let's add data pointer early. I will do the same for par/opaque and then moving few lines into register_master is internal change, caller won't need to be changed.
Some of my patches still need more work (unresolved comments), not all of them have +2 - not all of them ready to submit anyway. So maybe, if you submit this chain of 2 patches soon, I will rebase?
File spi.c:
https://review.coreboot.org/c/flashrom/+/54066/comment/ad3eb69b_66fd94fe
PS1, Line 151: if (data)
: rmst.spi.data = data;
> You can do it.
Oh great, I will do! I think, would better do it now, before I touched any par master, to get all benefits.
--
To view, visit https://review.coreboot.org/c/flashrom/+/54066
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f
Gerrit-Change-Number: 54066
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Wed, 12 May 2021 22:20:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Edward O'Callaghan, Anastasia Klimchuk.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/54066 )
Change subject: programmer: Smoothen register_spi_master() API
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
> Mine was CB:51761 which has everyone +2s and it was the end goal to submit after I do all refactorin […]
I know about CB:51761. It is focused on the shutdown pointer, though. I still
believe adding the data pointer early makes things easier.
Didn't mean to interrupt your work; I can rebase it if you'd push your patches
on a single branch.
--
To view, visit https://review.coreboot.org/c/flashrom/+/54066
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f
Gerrit-Change-Number: 54066
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Comment-Date: Wed, 12 May 2021 21:33:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment