Browse Source

Bugfix: Do not allocate spi_port on the Stack - EXC_BAD_ACCESS on OS X

Nate Woolls 12 years ago
parent
commit
14e9b43d75
3 changed files with 41 additions and 18 deletions
  1. 21 10
      driver-hashbuster.c
  2. 19 8
      driver-littlefury.c
  3. 1 0
      spidevc.h

+ 21 - 10
driver-hashbuster.c

@@ -146,6 +146,25 @@ bool hashbuster_lowl_match(const struct lowlevel_device_info * const info)
 	return lowlevel_match_lowlproduct(info, &lowl_hid, HASHBUSTER_USB_PRODUCT);
 	return lowlevel_match_lowlproduct(info, &lowl_hid, HASHBUSTER_USB_PRODUCT);
 }
 }
 
 
+static
+int hashbuster_chip_count(hid_device *h)
+{
+	/* Do not allocate spi_port on the Stack - EXC_BAD_ACCESS on OS X */
+	struct spi_port *spi = malloc(sizeof(*spi));
+	spi->txrx = hashbuster_spi_txrx;
+	spi->userp = h;
+	spi->repr = hashbuster_drv.dname;
+	spi->logprio = LOG_DEBUG;
+	spi->speed = 100000;
+	spi->mode = 0;
+	
+	const int chip_count = libbitfury_detectChips1(spi);
+	
+	free(spi);
+	
+	return chip_count;
+}
+
 static
 static
 bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 {
 {
@@ -170,16 +189,8 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 	if ((!hashbuster_io(h, buf, buf)) || buf[1] != 0x07)
 	if ((!hashbuster_io(h, buf, buf)) || buf[1] != 0x07)
 		applogr(false, LOG_DEBUG, "%s: Identify sequence didn't match on %s",
 		applogr(false, LOG_DEBUG, "%s: Identify sequence didn't match on %s",
 		        __func__, path);
 		        __func__, path);
-	
-	struct spi_port spi = {
-		.txrx = hashbuster_spi_txrx,
-		.userp = h,
-		.repr = hashbuster_drv.dname,
-		.logprio = LOG_DEBUG,
-		.speed = 100000,
-		.mode = 0,
-	};
-	const int chip_n = libbitfury_detectChips1(&spi);
+		
+	const int chip_n = hashbuster_chip_count(h);
 	
 	
 	hid_close(h);
 	hid_close(h);
 	
 	

+ 19 - 8
driver-littlefury.c

@@ -229,13 +229,29 @@ bool littlefury_lowl_match(const struct lowlevel_device_info * const info)
 	return lowlevel_match_product(info, "LittleFury");
 	return lowlevel_match_product(info, "LittleFury");
 }
 }
 
 
+static
+int littlefury_chip_count(struct cgpu_info * const info)
+{
+	/* Do not allocate spi_port on the Stack - EXC_BAD_ACCESS on OS X */
+	struct spi_port *spi = malloc(sizeof(*spi));
+	spi->txrx = littlefury_txrx;
+	spi->cgpu = info;
+	spi->repr = littlefury_drv.dname;
+	spi->logprio = LOG_DEBUG;
+	
+	const int chip_count = libbitfury_detectChips1(spi);
+	
+	free(spi);
+	
+	return chip_count;
+}
+
 static
 static
 bool littlefury_detect_one(const char *devpath)
 bool littlefury_detect_one(const char *devpath)
 {
 {
 	int fd, chips;
 	int fd, chips;
 	uint8_t buf[255];
 	uint8_t buf[255];
 	uint16_t bufsz;
 	uint16_t bufsz;
-	struct spi_port spi;
 	struct cgpu_info dummy;
 	struct cgpu_info dummy;
 	char *devname;
 	char *devname;
 	
 	
@@ -271,14 +287,9 @@ bool littlefury_detect_one(const char *devpath)
 	
 	
 	dummy.device = &dummy;
 	dummy.device = &dummy;
 	dummy.device_fd = fd;
 	dummy.device_fd = fd;
-	spi = (struct spi_port){
-		.txrx = littlefury_txrx,
-		.cgpu = &dummy,
-		.repr = littlefury_drv.dname,
-		.logprio = LOG_DEBUG,
-	};
 	
 	
-	chips = libbitfury_detectChips1(&spi);
+	chips = littlefury_chip_count(&dummy);
+	
 	if (!chips) {
 	if (!chips) {
 		applog(LOG_WARNING, "%s: No Bitfury chips detected on %s",
 		applog(LOG_WARNING, "%s: No Bitfury chips detected on %s",
 		       littlefury_drv.dname, devpath);
 		       littlefury_drv.dname, devpath);

+ 1 - 0
spidevc.h

@@ -10,6 +10,7 @@
 /* Initialize SPI using this function */
 /* Initialize SPI using this function */
 void spi_init(void);
 void spi_init(void);
 
 
+/* Do not allocate spi_port on the Stack - EXC_BAD_ACCESS on OS X */
 struct spi_port {
 struct spi_port {
 	/* TX-RX single frame */
 	/* TX-RX single frame */
 	bool (*txrx)(struct spi_port *port);
 	bool (*txrx)(struct spi_port *port);