Attention is currently required from: Nico Huber, Edward O'Callaghan, Angel Pons. Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52958 )
Change subject: buspirate_spi.c: Refactor singleton states into reentrant pattern ......................................................................
Patch Set 3:
(2 comments)
File buspirate_spi.c:
https://review.coreboot.org/c/flashrom/+/52958/comment/21f643f3_6ce3fdfa PS3, Line 58: unsigned char **bp_commbuf
I'd just pass a pointer to `struct bp_spi_data`
I was considering the idea to pass a pointer to `struct bp_spi_data` into buspirate_commbuf_grow but it didn't look great [to me] in init function.
Init function is quite long, and I wanted to use local variables for bp_commbuf and bp_commbufsize in init function to minimize diffs and noise. But at the same time, buspirate_commbuf_grow is called twice in the middle of init function, and each of those calls can change the pointer and the size. So, if I would need to pass data struct into buspirate_commbuf_grow, and also using local variables during init, that would mean: assigning local values into data, calling buspirate_commbuf_grow, and then assigning updated values from data into local variables.
https://review.coreboot.org/c/flashrom/+/52958/comment/f8d568a4_c90df3f2 PS3, Line 221: unsigned char *const bp_commbuf = bp_data->bp_commbuf;
I thought that buspirate_commbuf_grow can change the pointer, and I can have this local variable as […]
As I learned today from C standard, realloc can change the pointer. And because I want this to be a constant pointer, I only can define it after the call to buspirate_commbuf_grow (because it does realloc).