Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spi: misaligned payload on stack #3

Open
bradfitz opened this issue Dec 23, 2015 · 0 comments
Open

spi: misaligned payload on stack #3

bradfitz opened this issue Dec 23, 2015 · 0 comments

Comments

@bradfitz
Copy link

Sorry for lack of proper fix and pull request, but so I don't forget this:

diff --git a/spi/spi.go b/spi/spi.go
index 3eca73e..69d165d 100644
--- a/spi/spi.go
+++ b/spi/spi.go
@@ -109,10 +109,12 @@ func (d *Device) Sync() error {
        return d.f.Sync()
 }

+var used *payload
+
 // Do does a duplex transmission to write to the SPI device and read
 // len(buf) numbers of bytes.
 func (d *Device) Do(buf []byte, delay time.Duration) error {
-       p := payload{
+       p := &payload{
                tx:          uint64(uintptr(unsafe.Pointer(&buf[0]))),
                rx:          uint64(uintptr(unsafe.Pointer(&buf[0]))),
                length:      uint32(len(buf)),
@@ -120,7 +122,8 @@ func (d *Device) Do(buf []byte, delay time.Duration) error {
                delay:       uint16(delay.Nanoseconds() / 1000),
                bitsPerWord: d.bitsPerWord,
        }
-       return d.ioctl(msgArg(1), uintptr(unsafe.Pointer(&p)))
+       used = p // force escape
+       return d.ioctl(msgArg(1), uintptr(unsafe.Pointer(p)))
 }

 // Close closes the SPI device and releases related resources.

Totally the wrong way to fix it. I was lazy and impatient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant