Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 918644 Details for
Bug 913203
Load i2c-dev module when i2cdetect is executed
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
updated patch
i2c-tools-3.1.0-load-i2c-dev-mod.patch (text/plain), 6.34 KB, created by
Michal Minar
on 2014-07-17 09:13:35 UTC
(
hide
)
Description:
updated patch
Filename:
MIME Type:
Creator:
Michal Minar
Created:
2014-07-17 09:13:35 UTC
Size:
6.34 KB
patch
obsolete
>Index: i2c-tools-3.1.0/tools/i2cbusses.c >=================================================================== >--- i2c-tools-3.1.0.orig/tools/i2cbusses.c >+++ i2c-tools-3.1.0/tools/i2cbusses.c >@@ -37,9 +37,16 @@ > #include <dirent.h> > #include <fcntl.h> > #include <errno.h> >+#ifdef USE_LIBKMOD >+ #include <libkmod.h> >+#endif > #include "i2cbusses.h" > #include <linux/i2c-dev.h> > >+#define BUFLEN (NAME_MAX > 512 ? NAME_MAX : 512) >+#define I2C_DEV_MOD_NAME "i2c_dev" >+#define I2C_DEV_SUBPATH "/class/i2c-dev" >+ > enum adt { adt_dummy, adt_isa, adt_i2c, adt_smbus, adt_unknown }; > > struct adap_type { >@@ -60,6 +67,142 @@ static struct adap_type adap_types[5] = > .algo = "N/A", }, > }; > >+/* Get and cache sysfs mount point. */ >+static const char *get_sysfs_mount_point(void) { >+ static const char *mp = NULL; >+ >+ if (mp == NULL) { >+ char sysfs[NAME_MAX]; >+ char fstype[NAME_MAX]; >+ char line[BUFLEN]; >+ FILE *f; >+ >+ if ((f = fopen("/proc/mounts", "r")) == NULL) { >+ perror("failed to read /proc/mounts: "); >+ goto done; >+ } >+ while (fgets(line, BUFLEN, f)) { >+ sscanf(line, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfs, fstype); >+ if (strcasecmp(fstype, "sysfs") == 0) { >+ mp = strdup(sysfs); >+ if (mp == NULL) >+ perror("strdup: "); >+ break; >+ } >+ } >+ fclose(f); >+ } >+done: >+ return mp; >+} >+ >+/* Get an absolute path of i2c device directory. Free the result when not >+ * needed. */ >+static char *get_i2c_dev_path(void) { >+ char *path = NULL; >+ int mplen, splen; >+ const char *mp = get_sysfs_mount_point(); >+ >+ if (mp != NULL) { >+ mplen = strlen(mp); >+ splen = strlen(I2C_DEV_SUBPATH); >+ path = malloc(mplen + splen + 1); >+ if (path == NULL) { >+ perror("malloc: "); >+ } else { >+ strncpy(path, mp, mplen); >+ strncpy(path + mplen, I2C_DEV_SUBPATH, splen); >+ path[mplen+splen] = '\0'; >+ } >+ } >+ return path; >+} >+ >+/** >+ * Try to load i2c_dev kernel mode. Do nothing if module is already loaded. >+ * Returns 1 on success, 0 otherwise. >+ */ >+static int try_load_i2c_dev_mod(void) { >+ int err = 0, loaded = 0; >+ char errbuf[BUFLEN] = { 0 }; >+#ifdef USE_LIBKMOD >+ int flags = 0; >+ struct kmod_ctx *ctx; >+ struct kmod_list *l, *list = NULL; >+ >+ ctx = kmod_new(NULL, NULL); >+ if (!ctx) { >+ snprintf(errbuf, BUFLEN, "kmod_new() failed!"); >+ goto done; >+ } >+ if (kmod_module_new_from_lookup(ctx, I2C_DEV_MOD_NAME, &list) < 0 || list == NULL) { >+ snprintf(errbuf, BUFLEN, I2C_DEV_MOD_NAME " module lookup failed"); >+ goto ctx_unref; >+ } >+ >+ flags |= KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY; >+ kmod_list_foreach(l, list) { >+ struct kmod_module *mod = kmod_module_get_module(l); >+ err = kmod_module_probe_insert_module(mod, flags, NULL, NULL, NULL, NULL); >+ if (err == -ENOENT) { >+ snprintf(errbuf, BUFLEN, >+ "unknown symbol in module \"%s\", or unknown parameter (see dmesg)", >+ kmod_module_get_name(mod)); >+ } else if (err < 0) { >+ snprintf(errbuf, BUFLEN, "(module %s): %s", >+ kmod_module_get_name(mod), strerror(-err)); >+ } else { >+ kmod_module_unref(mod); >+ ++loaded; >+ break; >+ } >+ kmod_module_unref(mod); >+ } >+ >+ kmod_module_unref_list(list); >+ctx_unref: >+ kmod_unref(ctx); >+#else /* Try to load the module with modprobe. */ >+ struct stat st; >+ char *dev_path = get_i2c_dev_path(); >+ >+ /* First check whether the module is already loaded or built-in. */ >+ if (dev_path == NULL) >+ goto done; >+ err = stat(dev_path, &st); >+ if (err < 0) { >+ if (errno != ENOENT) { >+ snprintf(errbuf, BUFLEN, "can not stat \"%s\": %s", dev_path, >+ strerror(errno)); >+ goto err; >+ } else { >+ err = 0; >+ } >+ } else { >+ ++loaded; >+ goto done; >+ } >+ >+ err = system("modprobe " I2C_DEV_MOD_NAME); >+ if (err < 0) { >+ snprintf(errbuf, BUFLEN, "failed to execute modprobe command"); >+ } else if (err > 0) { >+ snprintf(errbuf, BUFLEN, "modprobe command exited with code %d", >+ WEXITSTATUS(err)); >+ } else { >+ ++loaded; >+ goto done; >+ } >+ >+err: >+#endif >+ if (errbuf[0]) >+ fprintf(stderr, "Failed to load required " I2C_DEV_MOD_NAME >+ " kernel module: %s\n", errbuf); >+done: >+ return loaded; >+} >+ > static enum adt i2c_get_funcs(int i2cbus) > { > unsigned long funcs; >@@ -132,8 +275,7 @@ struct i2c_adap *gather_i2c_busses(void) > struct dirent *de, *dde; > DIR *dir, *ddir; > FILE *f; >- char fstype[NAME_MAX], sysfs[NAME_MAX], n[NAME_MAX]; >- int foundsysfs = 0; >+ char *sysfs = NULL, n[NAME_MAX]; > int count=0; > struct i2c_adap *adapters; > >@@ -185,29 +327,19 @@ struct i2c_adap *gather_i2c_busses(void) > goto done; > } > >- /* look in sysfs */ >- /* First figure out where sysfs was mounted */ >- if ((f = fopen("/proc/mounts", "r")) == NULL) { >+ sysfs = get_i2c_dev_path(); >+ if (sysfs == NULL) > goto done; >- } >- while (fgets(n, NAME_MAX, f)) { >- sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfs, fstype); >- if (strcasecmp(fstype, "sysfs") == 0) { >- foundsysfs++; >- break; >- } >- } >- fclose(f); >- if (! foundsysfs) { >- goto done; >- } > > /* Bus numbers in i2c-adapter don't necessarily match those in > i2c-dev and what we really care about are the i2c-dev numbers. > Unfortunately the names are harder to get in i2c-dev */ >- strcat(sysfs, "/class/i2c-dev"); >- if(!(dir = opendir(sysfs))) >- goto done; >+ if(!(dir = opendir(sysfs))) { >+ if (!try_load_i2c_dev_mod()) >+ goto done; >+ if ((!(dir = opendir(sysfs)))) >+ goto done; >+ } > /* go through the busses */ > while ((de = readdir(dir)) != NULL) { > if (!strcmp(de->d_name, ".")) >@@ -272,14 +404,15 @@ found: > /* We need more space */ > adapters = more_adapters(adapters, count + 1); > if (!adapters) >- return NULL; >+ goto done; > } > > adapters[count].nr = i2cbus; > adapters[count].name = strdup(s); > if (adapters[count].name == NULL) { > free_adapters(adapters); >- return NULL; >+ adapters = NULL; >+ goto done; > } > adapters[count].funcs = adap_types[type].funcs; > adapters[count].algo = adap_types[type].algo; >@@ -289,6 +422,7 @@ found: > closedir(dir); > > done: >+ free(sysfs); > return adapters; > } > >Index: i2c-tools-3.1.0/tools/Module.mk >=================================================================== >--- i2c-tools-3.1.0.orig/tools/Module.mk >+++ i2c-tools-3.1.0/tools/Module.mk >@@ -15,6 +15,11 @@ TOOLS_CFLAGS := -Wstrict-prototypes -Wsh > > TOOLS_TARGETS := i2cdetect i2cdump i2cset i2cget > >+ifeq ($(shell pkg-config --exists libkmod && echo 1), 1) >+ TOOLS_CFLAGS += $(shell pkg-config --cflags libkmod) -DUSE_LIBKMOD >+ LDFLAGS += $(shell pkg-config --libs libkmod) >+endif >+ > # > # Programs > #
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 913203
:
902419
| 918644