svn commit: r311342 - stable/11/sys/dev/spibus

Oleksandr Tymoshenko gonzo at FreeBSD.org
Thu Jan 5 00:26:59 UTC 2017


Author: gonzo
Date: Thu Jan  5 00:26:57 2017
New Revision: 311342
URL: https://svnweb.freebsd.org/changeset/base/311342

Log:
  MFC r310170, r310492
  
  r310170:
  [spigen] Make "data" part of spigen_transfer optional
  
  Make st_data part of spigen_transfer optional by letting pass zero length
  and NULL pointer. SPI controller drivers handle this case fine.
  
  r310492:
  [spigen] Fix spigen attaching as a driver for SPI devices nodes in FDT
  
  Return BUS_PROBE_NOWILDCARD in probe method to make sure that spigen
  attaches only to the device created in identify method.
  
  Before this change spigen probe method used to return 0 which meant it
  competed with other drivers to be attached to the devices created for
  child nodes of SPI bus node in FDT.
  
  Reported by:	Daniel Braniss

Modified:
  stable/11/sys/dev/spibus/spigen.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/spibus/spigen.c
==============================================================================
--- stable/11/sys/dev/spibus/spigen.c	Thu Jan  5 00:08:04 2017	(r311341)
+++ stable/11/sys/dev/spibus/spigen.c	Thu Jan  5 00:26:57 2017	(r311342)
@@ -68,8 +68,10 @@ struct spigen_softc {
 static int
 spigen_probe(device_t dev)
 {
+
 	device_set_desc(dev, "SPI Generic IO");
-	return (0);
+
+	return (BUS_PROBE_NOWILDCARD);
 }
 
 static int spigen_open(struct cdev *, int, int, struct thread *);
@@ -191,7 +193,7 @@ spigen_transfer(struct cdev *cdev, struc
 	int error = 0;
 
 	mtx_lock(&sc->sc_mtx);
-	if (st->st_command.iov_len == 0 || st->st_data.iov_len == 0)
+	if (st->st_command.iov_len == 0)
 		error = EINVAL;
 	else if (st->st_command.iov_len > sc->sc_command_length_max ||
 	    st->st_data.iov_len > sc->sc_data_length_max)
@@ -208,16 +210,20 @@ spigen_transfer(struct cdev *cdev, struc
 	    M_DEVBUF, M_WAITOK);
 	if (transfer.tx_cmd == NULL)
 		return (ENOMEM);
-	transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
-	    M_DEVBUF, M_WAITOK);
-	if (transfer.tx_data == NULL) {
-		free(transfer.tx_cmd, M_DEVBUF);
-		return (ENOMEM);
+	if (st->st_data.iov_len > 0) {
+		transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
+		    M_DEVBUF, M_WAITOK);
+		if (transfer.tx_data == NULL) {
+			free(transfer.tx_cmd, M_DEVBUF);
+			return (ENOMEM);
+		}
 	}
+	else
+		transfer.tx_data = transfer.rx_data = NULL;
 
 	error = copyin(st->st_command.iov_base, transfer.tx_cmd,
 	    transfer.tx_cmd_sz = transfer.rx_cmd_sz = st->st_command.iov_len);	
-	if (error == 0)
+	if ((error == 0) && (st->st_data.iov_len > 0))
 		error = copyin(st->st_data.iov_base, transfer.tx_data,
 		    transfer.tx_data_sz = transfer.rx_data_sz =
 		                          st->st_data.iov_len);	
@@ -226,7 +232,7 @@ spigen_transfer(struct cdev *cdev, struc
 	if (error == 0) {
 		error = copyout(transfer.rx_cmd, st->st_command.iov_base,
 		    transfer.rx_cmd_sz);
-		if (error == 0)
+		if ((error == 0) && (st->st_data.iov_len > 0))
 			error = copyout(transfer.rx_data, st->st_data.iov_base,
 			    transfer.rx_data_sz);
 	}


More information about the svn-src-stable-11 mailing list