Fix a number of problems in mstarddc_spi.c

Coverity has brought up the following problems:

mstarddc_spi_send_command():
 - CID 1270702: bad comparison of malloced pointer 'cmd'.
 - CID 1270701: a NULL pointer dereference possible because of above.

Simply checking the return value of malloc in a valid way fixes both problems.

mstarddc_spi_init():
 - CID 1270699 and 1270700: Memory leak of i2c_device.

This patch revamps the function in various ways to fix these issues and some
other irritating bits.
It reduces scopes of variables where possible, pushes the code towards our
coding standards and introduces a label-based resource cleanup at the end.

Corresponding to flashrom svn r1885.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Alexandre Boeglin <alex@boeglin.org>
1 file changed