Re: enc interface errno

2013-09-27 Thread Mike Belopuhov
On 27 September 2013 15:24, Alexander Bluhm alexander.bl...@gmx.net wrote:
 Hi,

 The error return codes for the enc interface seem quite inconsistent.
 Always return the appropriate errno.

 ok?

 bluhm


OK



Re: enc interface errno

2013-09-27 Thread Reyk Floeter
On Fri, Sep 27, 2013 at 03:24:25PM +0200, Alexander Bluhm wrote:
 The error return codes for the enc interface seem quite inconsistent.
 Always return the appropriate errno.
 
 ok?
 

OK

Reyk

 bluhm
 
 Index: net/if_enc.c
 ===
 RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_enc.c,v
 retrieving revision 1.52
 diff -u -p -u -p -r1.52 if_enc.c
 --- net/if_enc.c  3 Jul 2010 04:44:51 -   1.52
 +++ net/if_enc.c  27 Sep 2013 13:01:19 -
 @@ -72,13 +72,14 @@ enc_clone_create(struct if_clone *ifc, i
   struct ifnet*ifp;
   struct ifnet**new;
   size_t   newlen;
 + int  error;
  
   if (unit  ENC_MAX_UNITS)
   return (EINVAL);
  
   if ((sc = malloc(sizeof(struct enc_softc),
   M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
 - return (ENOMEM);
 + return (ENOBUFS);
  
   sc-sc_unit = unit;
  
 @@ -102,17 +103,17 @@ enc_clone_create(struct if_clone *ifc, i
   bpfattach(ifp-if_bpf, ifp, DLT_ENC, ENC_HDRLEN);
  #endif
  
 - if (enc_setif(ifp, 0) != 0) {
 + if ((error = enc_setif(ifp, 0)) != 0) {
   if_detach(ifp);
   free(sc, M_DEVBUF);
 - return (-1);
 + return (error);
   }
  
   if (unit == 0 || unit  enc_max_unit) {
   newlen = sizeof(struct ifnet *) * (unit + 1);
  
   if ((new = malloc(newlen, M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
 - return (-1);
 + return (ENOBUFS);
   if (enc_allifps != NULL) {
   memcpy(new, enc_allifps,
   sizeof(struct ifnet *) * (enc_max_unit + 1));
 @@ -172,7 +173,7 @@ int
  enc_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
  {
   struct ifreq*ifr = (struct ifreq *)data;
 - int  error = 0;
 + int  error;
  
   switch (cmd) {
   case SIOCAIFADDR:
 @@ -238,13 +239,13 @@ enc_setif(struct ifnet *ifp, u_int id)
   return (0);
  
   if (id  RT_TABLEID_MAX)
 - return (-1);
 + return (EINVAL);
  
   if (id == 0 || id  enc_max_id) {
   newlen = sizeof(struct ifnet *) * (id + 1);
  
   if ((new = malloc(newlen, M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
 - return (-1);
 + return (ENOBUFS);
   if (enc_ifps != NULL) {
   memcpy(new, enc_ifps,
   sizeof(struct ifnet *) * (enc_max_id + 1));
 



Re: enc interface errno

2013-09-27 Thread Alexander Bluhm
On Fri, Sep 27, 2013 at 12:00:40PM -0400, Kenneth R Westerback wrote:
 I'm not sure what the 'rule' is regarding ENOMEM and ENOBUFS, but
 ENOMEN seems more appropriate to me.

man 2 errno

 12 ENOMEM Cannot allocate memory. The new process image required more
 memory than was allowed by the hardware or by system-imposed
 memory management constraints.  A lack of swap space is normally
 temporary; however, a lack of core is not.  Soft limits may be
 increased to their corresponding hard limits.

 55 ENOBUFS No buffer space available. An operation on a socket or pipe
 was not performed because the system lacked sufficient buffer
 space or because a queue was full.

According to this, ENOMEM looks very much like memory allocation
failure for the user space.  In my case we ran out of network device
memory, so I think ENOBUFS is more appropriate.

The kernel code is not very consistent there.  Developers are tempted
to use ENOMEM when malloc(9) fails, but the man page says something
different.

bluhm



Re: enc interface errno

2013-09-27 Thread Kenneth R Westerback
On Fri, Sep 27, 2013 at 06:56:04PM +0200, Alexander Bluhm wrote:
 On Fri, Sep 27, 2013 at 12:00:40PM -0400, Kenneth R Westerback wrote:
  I'm not sure what the 'rule' is regarding ENOMEM and ENOBUFS, but
  ENOMEN seems more appropriate to me.
 
 man 2 errno
 
  12 ENOMEM Cannot allocate memory. The new process image required more
  memory than was allowed by the hardware or by system-imposed
  memory management constraints.  A lack of swap space is normally
  temporary; however, a lack of core is not.  Soft limits may be
  increased to their corresponding hard limits.
 
  55 ENOBUFS No buffer space available. An operation on a socket or pipe
  was not performed because the system lacked sufficient buffer
  space or because a queue was full.
 
 According to this, ENOMEM looks very much like memory allocation
 failure for the user space.  In my case we ran out of network device
 memory, so I think ENOBUFS is more appropriate.
 
 The kernel code is not very consistent there.  Developers are tempted
 to use ENOMEM when malloc(9) fails, but the man page says something
 different.
 
 bluhm

bikeshed
But how does the failure to allocate a softc relate to a socket or pipe
because the system lacked sufficient buffer space? I read 'buffer space'
as related to mbufs. Of which I don't think softc's are composed.
/bikeshed

 Ken