source: rtems/cpukit/libi2c/libi2c.c @ 54a3c4d

4.10
Last change on this file since 54a3c4d was 54a3c4d, checked in by Joel Sherrill <joel.sherrill@…>, on 06/21/10 at 16:27:12

2010-06-21 Joel Sherrill <joel.sherrilL@…>

PR 1554/cpukit
Coverity Id 17

  • libi2c/libi2c.c: Fix memory leak on error.
  • Property mode set to 100644
File size: 18.7 KB
Line 
1/* $Id$ */
2
3/* libi2c Implementation */
4
5/*
6 * Authorship
7 * ----------
8 * This software was created by
9 *     Till Straumann <strauman@slac.stanford.edu>, 2005,
10 *         Stanford Linear Accelerator Center, Stanford University.
11 *
12 * Acknowledgement of sponsorship
13 * ------------------------------
14 * This software was produced by
15 *     the Stanford Linear Accelerator Center, Stanford University,
16 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
17 *
18 * Government disclaimer of liability
19 * ----------------------------------
20 * Neither the United States nor the United States Department of Energy,
21 * nor any of their employees, makes any warranty, express or implied, or
22 * assumes any legal liability or responsibility for the accuracy,
23 * completeness, or usefulness of any data, apparatus, product, or process
24 * disclosed, or represents that its use would not infringe privately owned
25 * rights.
26 *
27 * Stanford disclaimer of liability
28 * --------------------------------
29 * Stanford University makes no representations or warranties, express or
30 * implied, nor assumes any liability for the use of this software.
31 *
32 * Stanford disclaimer of copyright
33 * --------------------------------
34 * Stanford University, owner of the copyright, hereby disclaims its
35 * copyright and all other rights in this software.  Hence, anyone may
36 * freely use it for any purpose without restriction.
37 *
38 * Maintenance of notices
39 * ----------------------
40 * In the interest of clarity regarding the origin and status of this
41 * SLAC software, this and all the preceding Stanford University notices
42 * are to remain affixed to any copy or derivative of this software made
43 * or distributed by the recipient and are to be affixed to any copy of
44 * software made or distributed by the recipient that contains a copy or
45 * derivative of this software.
46 *
47 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
48 */
49/*
50 * adaptations to also handle SPI devices
51 * by Thomas Doerfler, embedded brains GmbH, Puchheim, Germany
52 */
53#if HAVE_CONFIG_H
54#include "config.h"
55#endif
56
57#include <string.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <errno.h>
61#include <assert.h>
62#include <stdarg.h>
63
64#include <rtems.h>
65#include <rtems/error.h>
66#include <rtems/bspIo.h>
67#include <rtems/libio.h>
68
69#include <rtems/libi2c.h>
70
71#define DRVNM "libi2c: "
72
73#define MAX_NO_BUSSES   8       /* Also limited by the macro building minor numbers */
74#define MAX_NO_DRIVERS  16      /* Number of high level drivers we support          */
75
76#define MINOR2ADDR(minor)       ((minor)&((1<<10)-1))
77#define MINOR2BUS(minor)        (((minor)>>10)&7)
78#define MINOR2DRV(minor)        ((minor)>>13)
79
80/* Check the 'minor' argument, i.e., verify that
81 * we have a driver connected
82 */
83#define DECL_CHECKED_BH(b, bh, m, s)\
84        unsigned b = MINOR2BUS(m);              \
85        rtems_libi2c_bus_t      *bh;            \
86        if ( b >= MAX_NO_BUSSES || 0 == (bh=busses[b].bush) ) { \
87                return s RTEMS_INVALID_NUMBER;  \
88        }
89
90#define DECL_CHECKED_DRV(d, b, m)       \
91        unsigned d = MINOR2DRV(m);              \
92        unsigned b = MINOR2BUS(m);              \
93        if (   b >= MAX_NO_BUSSES  || 0 == busses[b].bush       \
94                || d >  MAX_NO_DRIVERS || (d && 0 == drvs[d-1].drv )) {\
95                return RTEMS_INVALID_NUMBER;    \
96        }
97
98#define DISPATCH(rval, entry, dflt)     \
99        do {                            \
100                const rtems_driver_address_table *ops = drvs[--drv].drv->ops;   \
101                rval = ops->entry ? ops->entry(major,minor,arg) : dflt; \
102        } while (0)
103
104
105rtems_device_major_number rtems_libi2c_major;
106
107static bool is_initialized = false;
108
109static struct i2cbus
110{
111  rtems_libi2c_bus_t *bush;
112  volatile rtems_id mutex;      /* lock this across start -> stop */
113  volatile bool started;
114  char *name;
115} busses[MAX_NO_BUSSES] = { { NULL, RTEMS_ID_NONE, false, NULL } };
116
117static struct
118{
119  rtems_libi2c_drv_t *drv;
120} drvs[MAX_NO_DRIVERS] = { { NULL } };
121
122static rtems_id libmutex = RTEMS_ID_NONE;
123
124#define LOCK(m)         assert(!rtems_semaphore_obtain((m), RTEMS_WAIT, RTEMS_NO_TIMEOUT))
125#define UNLOCK(m)       rtems_semaphore_release((m))
126
127#define LIBLOCK()       LOCK(libmutex)
128#define LIBUNLOCK()     UNLOCK(libmutex)
129
130#define MUTEX_ATTS      \
131        (  RTEMS_PRIORITY                       \
132         | RTEMS_BINARY_SEMAPHORE       \
133         |RTEMS_INHERIT_PRIORITY        \
134         |RTEMS_NO_PRIORITY_CEILING     \
135         |RTEMS_LOCAL )
136
137/* During early stages of life, stdio is not available */
138
139static void
140safe_printf (const char *fmt, ...)
141{
142va_list ap;
143
144        va_start(ap, fmt);
145        if ( _System_state_Is_up( _System_state_Get() ) )
146                vfprintf( stderr, fmt, ap );
147        else
148                vprintk( fmt, ap );
149        va_end(ap);
150}
151
152static rtems_status_code
153mutexCreate (rtems_name nm, rtems_id *pm)
154{
155  rtems_status_code sc;
156
157  if (RTEMS_SUCCESSFUL !=
158      (sc = rtems_semaphore_create (nm, 1, MUTEX_ATTS, 0, pm))) {
159        if ( _System_state_Is_up( _System_state_Get() ) )
160        rtems_error (sc, DRVNM "Unable to create mutex\n");
161        else
162                printk (DRVNM "Unable to create mutex (status code %i)\n", sc);
163  }
164  return sc;
165}
166
167/* Lock a bus avoiding to have a mutex, which is mostly
168 * unused, hanging around all the time. We just create
169 * and delete it on the fly...
170 *
171 * ASSUMES: argument checked by caller
172 */
173
174static void
175lock_bus (int busno)
176{
177  struct i2cbus *bus = &busses[busno];
178
179  if (bus->mutex == RTEMS_ID_NONE) {
180    /*
181     * Nobody is holding the bus mutex - it's not there.  Create it on the fly.
182     */
183    LIBLOCK ();
184    if (bus->mutex == RTEMS_ID_NONE) {
185      rtems_id m = RTEMS_ID_NONE;
186      rtems_status_code sc = mutexCreate (
187        rtems_build_name ('i', '2', 'c', '0' + busno),
188        &m
189      );
190      if (sc != RTEMS_SUCCESSFUL) {
191        LIBUNLOCK ();
192        rtems_panic (DRVNM "Unable to create bus lock");
193        return;
194      }
195      bus->mutex = m;
196    }
197    LIBUNLOCK ();
198  }
199
200  /* Now lock this bus */
201  LOCK (bus->mutex);
202}
203
204static void
205unlock_bus (int busno)
206{
207  struct i2cbus *bus = &busses[busno];
208  UNLOCK (bus->mutex);
209}
210
211/* Note that 'arg' is always passed in as NULL */
212rtems_status_code
213rtems_i2c_init (rtems_device_major_number major, rtems_device_minor_number minor,
214          void *arg)
215{
216  rtems_status_code rval;
217  /* No busses or drivers can be registered at this point;
218   * avoid the macro aborting with an error
219  DECL_CHECKED_DRV (drv, busno, minor)
220   */
221
222  rval = mutexCreate (rtems_build_name ('l', 'I', '2', 'C'), &libmutex);
223
224  if ( RTEMS_SUCCESSFUL == rval ) {
225        is_initialized     = true;
226        rtems_libi2c_major = major;
227  } else {
228        libmutex = RTEMS_ID_NONE;
229  }
230  return rval;
231}
232
233rtems_status_code
234rtems_i2c_open (rtems_device_major_number major, rtems_device_minor_number minor,
235          void *arg)
236{
237  rtems_status_code rval;
238  DECL_CHECKED_DRV (drv, busno, minor)
239
240    if (0 == drv) {
241    rval = RTEMS_SUCCESSFUL;
242  } else {
243    DISPATCH (rval, open_entry, RTEMS_SUCCESSFUL);
244  }
245  return rval;
246}
247
248rtems_status_code
249rtems_i2c_close (rtems_device_major_number major, rtems_device_minor_number minor,
250           void *arg)
251{
252  rtems_status_code rval;
253  DECL_CHECKED_DRV (drv, busno, minor)
254
255    if (0 == drv) {
256    rval = RTEMS_SUCCESSFUL;
257  } else {
258    DISPATCH (rval, close_entry, RTEMS_SUCCESSFUL);
259  }
260  return rval;
261}
262
263rtems_status_code
264rtems_i2c_read (rtems_device_major_number major, rtems_device_minor_number minor,
265          void *arg)
266{
267  int rval;                     /* int so we can check for negative value */
268  rtems_libio_rw_args_t *rwargs = arg;
269  DECL_CHECKED_DRV (drv, busno, minor)
270
271    if (0 == rwargs->count) {
272    rwargs->bytes_moved = 0;
273    return RTEMS_SUCCESSFUL;
274  }
275
276  if (0 == drv) {
277    rval =
278      rtems_libi2c_start_read_bytes (minor, (unsigned char *) rwargs->buffer,
279                                     rwargs->count);
280    if (rval >= 0) {
281      rwargs->bytes_moved = rval;
282      rtems_libi2c_send_stop (minor);
283      rval = RTEMS_SUCCESSFUL;
284    } else {
285      rval = -rval;
286    }
287  } else {
288    DISPATCH (rval, read_entry, RTEMS_NOT_IMPLEMENTED);
289  }
290  return rval;
291}
292
293rtems_status_code
294rtems_i2c_write (rtems_device_major_number major, rtems_device_minor_number minor,
295           void *arg)
296{
297  int rval;                     /* int so we can check for negative value */
298  rtems_libio_rw_args_t *rwargs = arg;
299  DECL_CHECKED_DRV (drv, busno, minor)
300
301    if (0 == rwargs->count) {
302    rwargs->bytes_moved = 0;
303    return RTEMS_SUCCESSFUL;
304  }
305
306  if (0 == drv) {
307    rval =
308      rtems_libi2c_start_write_bytes (minor, (unsigned char *) rwargs->buffer,
309                                      rwargs->count);
310    if (rval >= 0) {
311      rwargs->bytes_moved = rval;
312      rtems_libi2c_send_stop (minor);
313      rval = RTEMS_SUCCESSFUL;
314    } else {
315      rval = -rval;
316    }
317  } else {
318    DISPATCH (rval, write_entry, RTEMS_NOT_IMPLEMENTED);
319  }
320  return rval;
321}
322
323rtems_status_code
324rtems_i2c_ioctl (rtems_device_major_number major, rtems_device_minor_number minor,
325           void *arg)
326{
327  rtems_status_code rval;
328  DECL_CHECKED_DRV (drv, busno, minor)
329
330    if (0 == drv) {
331    rval = RTEMS_NOT_IMPLEMENTED;
332  } else {
333    DISPATCH (rval, control_entry, RTEMS_NOT_IMPLEMENTED);
334  }
335  return rval;
336}
337
338
339/* Our ops just dispatch to the registered drivers */
340const rtems_driver_address_table rtems_libi2c_io_ops = {
341  initialization_entry:  rtems_i2c_init,
342  open_entry:            rtems_i2c_open,
343  close_entry:           rtems_i2c_close,
344  read_entry:            rtems_i2c_read,
345  write_entry:           rtems_i2c_write,
346  control_entry:         rtems_i2c_ioctl,
347};
348
349int
350rtems_libi2c_initialize (void)
351{
352  rtems_status_code sc;
353
354  if (is_initialized) {
355    /*
356     * already called before? then skip this step
357     */
358    return 0;
359  }
360
361  /* rtems_io_register_driver does NOT currently check nor report back
362   * the return code of the 'init' operation, so we cannot
363   * rely on return code since it may seem OK even if the driver 'init;
364   * op failed.
365   * Let 'init' handle 'is_initialized'...
366   */
367  sc = rtems_io_register_driver (0, &rtems_libi2c_io_ops, &rtems_libi2c_major);
368  if (RTEMS_SUCCESSFUL != sc) {
369    safe_printf(
370             DRVNM "Claiming driver slot failed (rtems status code %i)\n",
371             sc);
372    if (libmutex != RTEMS_ID_NONE) {
373      rtems_semaphore_delete (libmutex);
374    }
375    libmutex = RTEMS_ID_NONE;
376    is_initialized = false;
377    return -1;
378  }
379
380  return 0;
381}
382
383int
384rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus)
385{
386  int i;
387  rtems_status_code err;
388  char *nmcpy = malloc (name ? strlen (name) + 1 : 20);
389  char tmp, *chpt;
390  struct stat sbuf;
391
392  strcpy (nmcpy, name ? name : "/dev/i2c");
393
394
395  /* check */
396  if ('/' != *nmcpy) {
397    safe_printf ( DRVNM "Bad name: must be an absolute path starting with '/'\n");
398    free( nmcpy );
399    return -RTEMS_INVALID_NAME;
400  }
401  /* file must not exist */
402  if (!stat (nmcpy, &sbuf)) {
403    safe_printf ( DRVNM "Bad name: file exists already\n");
404    free( nmcpy );
405    return -RTEMS_INVALID_NAME;
406  }
407
408  /* we already verified that there is at least one '/' */
409  chpt = strrchr (nmcpy, '/') + 1;
410  tmp = *chpt;
411  *chpt = 0;
412  i = stat (nmcpy, &sbuf);
413  *chpt = tmp;
414  if (i) {
415    safe_printf ( DRVNM "Get %s status failed: %s\n",
416             nmcpy, strerror(errno));
417    free( nmcpy );
418    return -RTEMS_INVALID_NAME;
419  }
420  /* should be a directory since name terminates in '/' */
421
422
423  if (libmutex == RTEMS_ID_NONE) {
424    safe_printf ( DRVNM "Library not initialized\n");
425    free( nmcpy );
426    return -RTEMS_NOT_DEFINED;
427  }
428
429  if (bus == NULL || bus->size < sizeof (*bus)) {
430    safe_printf ( DRVNM "No bus-ops or size too small -- misconfiguration?\n");
431    free( nmcpy );
432    return -RTEMS_NOT_CONFIGURED;
433  }
434
435  LIBLOCK ();
436  for (i = 0; i < MAX_NO_BUSSES; i++) {
437    if (!busses[i].bush) {
438      /* found a free slot */
439      busses[i].bush = bus;
440      busses[i].mutex = RTEMS_ID_NONE;
441      busses[i].started = false;
442
443      if (!name)
444        sprintf (nmcpy + strlen (nmcpy), "%i", i);
445
446      if ((err = busses[i].bush->ops->init (busses[i].bush))) {
447        /* initialization failed */
448        i = -err;
449      } else {
450        busses[i].name = nmcpy;;
451        nmcpy = 0;
452      }
453
454      break;
455    }
456  }
457  LIBUNLOCK ();
458
459  if (i >= MAX_NO_BUSSES) {
460    i = -RTEMS_TOO_MANY;
461  }
462
463  free (nmcpy);
464
465  return i;
466}
467
468static int
469not_started (int busno)
470{
471  int rval;
472  lock_bus (busno);
473  rval = !busses[busno].started;
474  unlock_bus (busno);
475  return rval;
476}
477
478rtems_status_code
479rtems_libi2c_send_start (rtems_device_minor_number minor)
480{
481  int rval;
482  DECL_CHECKED_BH (busno, bush, minor, +)
483
484    lock_bus (busno);
485  rval = bush->ops->send_start (bush);
486
487  /* if this failed or is not the first start, unlock */
488  if (rval || busses[busno].started) {
489    /* HMM - what to do if the 1st start failed ?
490     * try to reset...
491     */
492    if (!busses[busno].started) {
493      /* just in case the bus driver fiddles with errno */
494      int errno_saved = errno;
495      bush->ops->init (bush);
496      errno = errno_saved;
497    } else if (rval) {
498      /* failed restart */
499      rtems_libi2c_send_stop (minor);
500    }
501    unlock_bus (busno);
502  } else {
503    /* successful 1st start; keep bus locked until stop is sent */
504    busses[busno].started = true;
505  }
506  return rval;
507}
508
509rtems_status_code
510rtems_libi2c_send_stop (rtems_device_minor_number minor)
511{
512  rtems_status_code rval;
513  DECL_CHECKED_BH (busno, bush, minor, +)
514
515    if (not_started (busno))
516    return RTEMS_NOT_OWNER_OF_RESOURCE;
517
518  rval = bush->ops->send_stop (bush);
519
520  busses[busno].started = false;
521
522  unlock_bus (busno);
523  return rval;
524}
525
526rtems_status_code
527rtems_libi2c_send_addr (rtems_device_minor_number minor, int rw)
528{
529  rtems_status_code sc;
530  DECL_CHECKED_BH (busno, bush, minor, +)
531
532    if (not_started (busno))
533    return RTEMS_NOT_OWNER_OF_RESOURCE;
534
535  sc = bush->ops->send_addr (bush, MINOR2ADDR (minor), rw);
536  if (RTEMS_SUCCESSFUL != sc)
537    rtems_libi2c_send_stop (minor);
538  return sc;
539}
540
541int
542rtems_libi2c_read_bytes (rtems_device_minor_number minor,
543                         unsigned char *bytes,
544                         int nbytes)
545{
546  int sc;
547  DECL_CHECKED_BH (busno, bush, minor, -)
548
549  if (not_started (busno))
550    return -RTEMS_NOT_OWNER_OF_RESOURCE;
551
552  sc = bush->ops->read_bytes (bush, bytes, nbytes);
553  if (sc < 0)
554    rtems_libi2c_send_stop (minor);
555  return sc;
556}
557
558int
559rtems_libi2c_write_bytes (rtems_device_minor_number minor,
560                          const unsigned char *bytes,
561                          int nbytes)
562{
563  int sc;
564  DECL_CHECKED_BH (busno, bush, minor, -)
565
566  if (not_started (busno))
567    return -RTEMS_NOT_OWNER_OF_RESOURCE;
568
569  sc = bush->ops->write_bytes (bush, (unsigned char *)bytes, nbytes);
570  if (sc < 0)
571    rtems_libi2c_send_stop (minor);
572  return sc;
573}
574
575int
576rtems_libi2c_ioctl (rtems_device_minor_number minor,
577                    int cmd,
578                    ...)
579{
580  va_list            ap;
581  int sc = 0;
582  void *args;
583  bool is_started = false;
584  DECL_CHECKED_BH (busno, bush, minor, -)
585
586  va_start(ap, cmd);
587  args = va_arg(ap, void *);
588
589  switch(cmd) {
590    /*
591     * add ioctls defined for this level here:
592     */
593
594  case RTEMS_LIBI2C_IOCTL_GET_DRV_T:
595    /*
596     * query driver table entry
597     */
598    *(rtems_libi2c_drv_t **)args = (drvs[MINOR2DRV(minor)-1].drv);
599    break;
600
601  case RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE:
602    if (not_started (busno))
603      return -RTEMS_NOT_OWNER_OF_RESOURCE;
604
605    /*
606     * address device, then set transfer mode and perform read_write transfer
607     */
608    /*
609     * perform start/address
610     */
611    if (sc == 0) {
612      sc = rtems_libi2c_send_start (minor);
613      is_started = (sc == 0);
614    }
615    /*
616     * set tfr mode
617     */
618    if (sc == 0) {
619      sc = bush->ops->ioctl
620        (bush,
621         RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
622         &((rtems_libi2c_tfm_read_write_t *)args)->tfr_mode);
623    }
624    /*
625     * perform read_write
626     */
627    if (sc == 0) {
628      sc = bush->ops->ioctl
629        (bush,
630         RTEMS_LIBI2C_IOCTL_READ_WRITE,
631         &((rtems_libi2c_tfm_read_write_t *)args)->rd_wr);
632    }
633    if ((sc < 0) && (is_started)) {
634      rtems_libi2c_send_stop (minor);
635    }
636    break;
637  default:
638    sc = bush->ops->ioctl (bush, cmd, args);
639    break;
640  }
641    return sc;
642}
643
644static int
645do_s_rw (rtems_device_minor_number minor,
646         unsigned char *bytes,
647         int nbytes,
648         int rw)
649{
650  rtems_status_code   sc;
651  rtems_libi2c_bus_t *bush;
652  int                 status;
653
654  if ((sc = rtems_libi2c_send_start (minor)))
655    return -sc;
656
657  /* at this point, we hold the bus and are sure the minor number is valid */
658  bush = busses[MINOR2BUS (minor)].bush;
659
660  if ((sc = bush->ops->send_addr (bush, MINOR2ADDR (minor), rw))) {
661    rtems_libi2c_send_stop (minor);
662    return -sc;
663  }
664
665  if (rw)
666    status = bush->ops->read_bytes (bush, bytes, nbytes);
667  else
668    status = bush->ops->write_bytes (bush, bytes, nbytes);
669
670  if (status < 0) {
671    rtems_libi2c_send_stop (minor);
672  }
673  return status;
674}
675
676int
677rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
678                               unsigned char *bytes,
679                               int nbytes)
680{
681  return do_s_rw (minor, bytes, nbytes, 1);
682}
683
684int
685rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
686                                const unsigned char *bytes,
687                                int nbytes)
688{
689  return do_s_rw (minor, (unsigned char *)bytes, nbytes, 0);
690}
691
692int
693rtems_libi2c_register_drv (const char *name, rtems_libi2c_drv_t * drvtbl,
694                           unsigned busno, unsigned i2caddr)
695{
696  int i;
697  rtems_status_code err;
698  rtems_device_minor_number minor;
699
700  if (libmutex == RTEMS_ID_NONE) {
701    safe_printf ( DRVNM "Library not initialized\n");
702    return -RTEMS_NOT_DEFINED;
703  }
704
705  if (name && strchr (name, '/')) {
706    safe_printf ( DRVNM "Invalid name: '%s' -- must not contain '/'\n", name);
707    return -RTEMS_INVALID_NAME;
708  }
709
710  if (busno >= MAX_NO_BUSSES || !busses[busno].bush || i2caddr >= 1 << 10) {
711    errno = EINVAL;
712    return -RTEMS_INVALID_NUMBER;
713  }
714
715  if (drvtbl == NULL || drvtbl->size < sizeof (*drvtbl)) {
716    safe_printf ( DRVNM "No driver table or size too small -- misconfiguration?\n");
717    return -RTEMS_NOT_CONFIGURED;
718  }
719
720  /* allocate slot */
721  LIBLOCK ();
722  for (i = 0; i < MAX_NO_DRIVERS; i++) {
723    /* driver # 0 is special, it is the built-in raw driver */
724    if (!drvs[i].drv) {
725      char *str;
726      dev_t dev;
727      uint32_t mode;
728
729      /* found a free slot; encode slot + 1 ! */
730      minor = ((i + 1) << 13) | RTEMS_LIBI2C_MAKE_MINOR (busno, i2caddr);
731
732      if (name) {
733        str = malloc (strlen (busses[busno].name) + strlen (name) + 2);
734        sprintf (str, "%s.%s", busses[busno].name, name);
735
736        dev = rtems_filesystem_make_dev_t (rtems_libi2c_major, minor);
737
738        mode = 0111 | S_IFCHR;
739        if (drvtbl->ops->read_entry)
740          mode |= 0444;
741        if (drvtbl->ops->write_entry)
742          mode |= 0222;
743
744        /* note that 'umask' is applied to 'mode' */
745        if (mknod (str, mode, dev)) {
746          safe_printf( DRVNM
747                   "Creating device node failed: %s; you can try to do it manually...\n",
748                   strerror (errno));
749        }
750
751        free (str);
752      }
753
754      drvs[i].drv = drvtbl;
755
756      if (drvtbl->ops->initialization_entry)
757        err =
758          drvs[i].drv->ops->initialization_entry (rtems_libi2c_major, minor,
759                                                  0);
760      else
761        err = RTEMS_SUCCESSFUL;
762
763      LIBUNLOCK ();
764      return err ? -err : minor;
765    }
766  }
767  LIBUNLOCK ();
768  return -RTEMS_TOO_MANY;
769}
Note: See TracBrowser for help on using the repository browser.