All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pelle Nilsson <per.nilsson@xelmo.com>
To: broonie@kernel.org
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	nios2-dev@lists.rocketboards.org
Subject: [PATCH] spi: bitbang: Make setup_transfer callback optional
Date: Mon, 13 Apr 2015 12:08:05 +0200	[thread overview]
Message-ID: <1428919685-14190-1-git-send-email-per.nilsson@xelmo.com> (raw)
In-Reply-To: <552B9045.4040709@xelmo.com>

spi-altera doesn't register this callback, and doesn't have a need for it,
but currently causes a NULL dereference when callback is called.
---
 drivers/spi/spi-bitbang.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index 5ef6638..d02057d 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -180,7 +180,7 @@ int spi_bitbang_setup(struct spi_device *spi)
 {
 	struct spi_bitbang_cs	*cs = spi->controller_state;
 	struct spi_bitbang	*bitbang;
-	int			retval;
+	int			retval = 0;
 	unsigned long		flags;
 
 	bitbang = spi_master_get_devdata(spi->master);
@@ -197,7 +197,8 @@ int spi_bitbang_setup(struct spi_device *spi)
 	if (!cs->txrx_word)
 		return -EINVAL;
 
-	retval = bitbang->setup_transfer(spi, NULL);
+	if (bitbang->setup_transfer)
+		retval = bitbang->setup_transfer(spi, NULL);
 	if (retval < 0)
 		return retval;
 
@@ -295,9 +296,11 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
 
 		/* init (-1) or override (1) transfer params */
 		if (do_setup != 0) {
-			status = bitbang->setup_transfer(spi, t);
-			if (status < 0)
-				break;
+			if (bitbang->setup_transfer) {
+				status = bitbang->setup_transfer(spi, t);
+				if (status < 0)
+					break;
+			}
 			if (do_setup == -1)
 				do_setup = 0;
 		}
-- 
1.9.1


WARNING: multiple messages have this Message-ID (diff)
From: Pelle Nilsson <per.nilsson-5TWeZ6kPplYAvxtiuMwx3w@public.gmane.org>
To: broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	nios2-dev-g9ZBwUv/Ih/yUk5EbOjzuce+I+R0W71w@public.gmane.org
Subject: [PATCH] spi: bitbang: Make setup_transfer callback optional
Date: Mon, 13 Apr 2015 12:08:05 +0200	[thread overview]
Message-ID: <1428919685-14190-1-git-send-email-per.nilsson@xelmo.com> (raw)
In-Reply-To: <552B9045.4040709-5TWeZ6kPplYAvxtiuMwx3w@public.gmane.org>

spi-altera doesn't register this callback, and doesn't have a need for it,
but currently causes a NULL dereference when callback is called.
---
 drivers/spi/spi-bitbang.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index 5ef6638..d02057d 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -180,7 +180,7 @@ int spi_bitbang_setup(struct spi_device *spi)
 {
 	struct spi_bitbang_cs	*cs = spi->controller_state;
 	struct spi_bitbang	*bitbang;
-	int			retval;
+	int			retval = 0;
 	unsigned long		flags;
 
 	bitbang = spi_master_get_devdata(spi->master);
@@ -197,7 +197,8 @@ int spi_bitbang_setup(struct spi_device *spi)
 	if (!cs->txrx_word)
 		return -EINVAL;
 
-	retval = bitbang->setup_transfer(spi, NULL);
+	if (bitbang->setup_transfer)
+		retval = bitbang->setup_transfer(spi, NULL);
 	if (retval < 0)
 		return retval;
 
@@ -295,9 +296,11 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
 
 		/* init (-1) or override (1) transfer params */
 		if (do_setup != 0) {
-			status = bitbang->setup_transfer(spi, t);
-			if (status < 0)
-				break;
+			if (bitbang->setup_transfer) {
+				status = bitbang->setup_transfer(spi, t);
+				if (status < 0)
+					break;
+			}
 			if (do_setup == -1)
 				do_setup = 0;
 		}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2015-04-13 10:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-09 15:03 [PATCH 0/1] Fix NULL pointer dereference Pelle Nilsson
2015-04-09 15:03 ` Pelle Nilsson
2015-04-09 15:03 ` [PATCH 1/1] spi: altera: Add empty implementation of setup_transfer callback Pelle Nilsson
2015-04-09 15:03   ` Pelle Nilsson
2015-04-09 15:40   ` Mark Brown
2015-04-09 15:40     ` Mark Brown
2015-04-09 15:50     ` Pelle Nilsson
2015-04-09 15:50       ` Pelle Nilsson
2015-04-09 16:10       ` Mark Brown
2015-04-09 16:10         ` Mark Brown
2015-04-13  9:45         ` Pelle Nilsson
2015-04-13 10:08           ` Pelle Nilsson [this message]
2015-04-13 10:08             ` [PATCH] spi: bitbang: Make setup_transfer callback optional Pelle Nilsson
2015-04-14  0:22             ` [Nios2-dev] " Ezequiel Garcia
2015-04-14  0:22               ` Ezequiel Garcia
2015-04-14 13:40             ` [PATCH v2] spi: bitbang: Make setup_transfer() " Pelle Nilsson
2015-04-14 13:40               ` Pelle Nilsson
2015-04-14 15:36               ` Ezequiel Garcia
2015-04-14 15:36                 ` Ezequiel Garcia
2015-04-18 11:00               ` Mark Brown
2015-04-18 11:00                 ` Mark Brown
2015-04-09 15:26 ` [PATCH 0/1] Fix NULL pointer dereference Mark Brown
2015-04-09 15:26   ` Mark Brown
2015-04-09 15:54 ` [PATCH v2] spi: altera: Add empty implementation of setup_transfer callback Pelle Nilsson
2015-04-09 15:54   ` Pelle Nilsson
2015-04-09 16:23   ` Mark Brown
2015-04-09 16:23     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428919685-14190-1-git-send-email-per.nilsson@xelmo.com \
    --to=per.nilsson@xelmo.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=nios2-dev@lists.rocketboards.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.