Skip to content

Commit 452f2e7

Browse files
committed
Buffer for SPI bus sysfs path too small
@kozga advised in issue #94 of a bug in get_spi_bus_path_number() > In version 1.0 declared path length is too low (50 bytes) > But for kernels 4.1 path length is 54 bytes. > In result, path is shortened to > '/sys/devices/platform/ocp/48030000.spi/spi_master/' > and function always return 1, > even if you try to open /dev/spidev2.x. These are the sysfs paths for the SPI bus 1 and 2 for Debian 8.6 with Linux 4.4.21-bone13 kernel: /sys/devices/platform/ocp/48030000.spi/spi_master/spi1/ /sys/devices/platform/ocp/481a0000.spi/spi_master/spi2/ I have fixed by increasing the size of path to MAX_PATH. MAX_PATH is defined as 256. This should provide enough extra margin for any future kernel changes in sysfs paths.
1 parent 12b79d7 commit 452f2e7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

source/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ BBIO_err build_path(const char *partial_path, const char *prefix, char *full_pat
392392

393393
int get_spi_bus_path_number(unsigned int spi)
394394
{
395-
char path[50];
395+
char path[MAX_PATH];
396396

397397
#ifdef BBBVERSION41
398398
strncpy(ocp_dir, "/sys/devices/platform/ocp", sizeof(ocp_dir));

source/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SOFTWARE.
4040
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
4141

4242
#define FILENAME_BUFFER_SIZE 128
43+
#define MAX_PATH 256
4344

4445
typedef enum {
4546
BBIO_OK, // No error
@@ -91,4 +92,4 @@ BBIO_err get_pwm_by_key(const char *key, pwm_t **pwm);
9192
int setup_error;
9293
int module_setup;
9394

94-
#endif
95+
#endif

0 commit comments

Comments
 (0)