Check if intf->cb->ec->destroy exists before calling it

Some systems use an EC destroy callback, for example, to close device
nodes in /dev. Currently this is the case for CrOS ECs which we
access via devfs.

However if platform setup is unsuccessful, for example if the CrOS
EC device node doesn't exist, then the destroy callback will still
be called and cause mosys to segfault.

(This is backported from CL:234042 for M39)

TEST=renamed /dev/cros_ec on nyan, ran mosys and it didn't segfault

Change-Id: I2eaf75a2caa0f4dadafbc013f850e7ac3209a356
Signed-off-by: David Hendricks <>
Reviewed-by: Shawn Nematbakhsh <>
3 files changed