On Thu, Apr 06, 2023 at 02:09:23PM +0200, Alexander Bluhm wrote:
> 
> On Thu, Apr 06, 2023 at 02:58:56PM +0800, Kevin Lo wrote:
> > The diff below adds M_CANFAIL to the flag passed to malloc() since we are 
> > able
> > to fail gracefully.
> 
> I would not call a return ENOMEM a gracefull fail.
> 
> Usually if we can wait with M_WAITOK and everyting is fine afterwards,
> that's a good solution.  Dealing with ENOMEM in upper layer is
> harder.  Someone has to retry or decide what to do.
> 
> What problem do you want to fix?
> 
> If the currently dead code, as the if is never taken, is your
> concern, just remove the if () return ENOMEM.

Sorry I may not have explained it clearly earlier.

The mallocarray(9) says:

M_CANFAIL
     In the M_WAITOK case, if not enough memory is available,
     return NULL instead of calling panic(9).  If mallocarray()
     detects an overflow or malloc() detects an excessive
     allocation, return NULL instead of calling panic(9).


I'd like to keep the mallocarray call unchanged so I add M_CANFAIL 
to the flags.

> > ok?
> > 
> > Index: sys/dev/pci/if_igc.c
> > ===================================================================
> > RCS file: /cvs/src/sys/dev/pci/if_igc.c,v
> > retrieving revision 1.12
> > diff -u -p -u -p -r1.12 if_igc.c
> > --- sys/dev/pci/if_igc.c    9 Mar 2023 00:13:47 -0000       1.12
> > +++ sys/dev/pci/if_igc.c    6 Apr 2023 06:50:43 -0000
> > @@ -1210,7 +1210,7 @@ igc_rxrinfo(struct igc_softc *sc, struct
> >     int error, i, n = 0;
> >  
> >     if ((ifr = mallocarray(sc->sc_nqueues, sizeof(*ifr), M_DEVBUF,
> > -       M_WAITOK | M_ZERO)) == NULL)
> > +       M_WAITOK | M_CANFAIL | M_ZERO)) == NULL)
> >             return ENOMEM;
> >  
> >     for (i = 0; i < sc->sc_nqueues; i++) {
> > Index: sys/dev/pci/if_ix.c
> > ===================================================================
> > RCS file: /cvs/src/sys/dev/pci/if_ix.c,v
> > retrieving revision 1.192
> > diff -u -p -u -p -r1.192 if_ix.c
> > --- sys/dev/pci/if_ix.c     6 Feb 2023 20:27:44 -0000       1.192
> > +++ sys/dev/pci/if_ix.c     6 Apr 2023 06:50:44 -0000
> > @@ -641,7 +641,7 @@ ixgbe_rxrinfo(struct ix_softc *sc, struc
> >  
> >     if (sc->num_queues > 1) {
> >             if ((ifr = mallocarray(sc->num_queues, sizeof(*ifr), M_DEVBUF,
> > -               M_WAITOK | M_ZERO)) == NULL)
> > +               M_WAITOK | M_CANFAIL | M_ZERO)) == NULL)
> >                     return (ENOMEM);
> >     } else
> >             ifr = &ifr1;
> > Index: sys/dev/pci/if_oce.c
> > ===================================================================
> > RCS file: /cvs/src/sys/dev/pci/if_oce.c,v
> > retrieving revision 1.106
> > diff -u -p -u -p -r1.106 if_oce.c
> > --- sys/dev/pci/if_oce.c    11 Mar 2022 18:00:48 -0000      1.106
> > +++ sys/dev/pci/if_oce.c    6 Apr 2023 06:50:44 -0000
> > @@ -903,7 +903,7 @@ oce_rxrinfo(struct oce_softc *sc, struct
> >  
> >     if (sc->sc_nrq > 1) {
> >             if ((ifr = mallocarray(sc->sc_nrq, sizeof(*ifr), M_DEVBUF,
> > -               M_WAITOK | M_ZERO)) == NULL)
> > +               M_WAITOK | M_CANFAIL | M_ZERO)) == NULL)
> >                     return (ENOMEM);
> >     } else
> >             ifr = &ifr1;
> 

Reply via email to