Nicholas Chin has uploaded this change for review.
ch347t_spi.c: Move ch347_device struct to flashctx
Signed-off-by: Nicholas Chin <nic.c3.14@gmail.com>
Change-Id: If3ff96dedd2b591200dd69f54df753668853beca
---
M ch347t_spi.c
1 file changed, 18 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/66/71066/1
diff --git a/ch347t_spi.c b/ch347t_spi.c
index 87c9bb4..45ac1df 100644
--- a/ch347t_spi.c
+++ b/ch347t_spi.c
@@ -2,6 +2,7 @@
* This file is part of the flashrom project.
*
* Copyright (C) 2022 qianfan Zhao <qianfanguijin@163.com>
+ * Copyright (C) 2022 Nicholas Chin <nic.c3.14@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,6 +16,7 @@
*/
#include <string.h>
+#include <stdlib.h>
#include <libusb.h>
#include "flash.h"
#include "platform.h"
@@ -318,10 +320,6 @@
return 0;
}
-static struct ch347_device ch347_device = {
- .handle = NULL,
-};
-
static const struct dev_entry devs_ch347t_spi[] = {
{0x1A86, 0x55DB, OK, "Winchiphead (WCH)", "CH347T"},
{0},
@@ -329,7 +327,7 @@
static int ch347t_spi_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr)
{
- struct ch347_device *dev = &ch347_device;
+ struct ch347_device *dev = flash->mst->spi.data;
int ret;
if (!dev->handle)
@@ -358,7 +356,7 @@
static int ch347t_spi_shutdown(void *data)
{
- struct ch347_device *dev = &ch347_device;
+ struct ch347_device *dev = data;
struct libusb_device_handle *handle = dev->handle;
if (!handle)
@@ -369,6 +367,7 @@
libusb_close(handle);
libusb_exit(NULL);
dev->handle = NULL;
+ free(data);
return 0;
}
@@ -387,15 +386,10 @@
static int ch347t_spi_init(const struct programmer_cfg *cfg)
{
- struct ch347_device *dev = &ch347_device;
- struct libusb_device_handle *handle;
+ struct ch347_device *dev = calloc(1, sizeof(*dev));
+ struct libusb_device_handle *handle = NULL;
int ret;
- if (dev->handle != NULL) {
- msg_cerr("%s: handle already set! Please report a bug at flashrom@flashrom.org\n", __func__);
- return -1;
- }
-
ret = libusb_init(NULL);
if (ret < 0) {
msg_perr("Couldn't initialize libusb!\n");
@@ -437,7 +431,7 @@
goto release_interface;
}
- return register_spi_master(&spi_master_ch347t_spi, NULL);
+ return register_spi_master(&spi_master_ch347t_spi, dev);
release_interface:
libusb_release_interface(handle, 0);
To view, visit change 71066. To unsubscribe, or for help writing mail filters, visit settings.