From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751603AbdITGuM (ORCPT ); Wed, 20 Sep 2017 02:50:12 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:34162 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbdITGuK (ORCPT ); Wed, 20 Sep 2017 02:50:10 -0400 X-Google-Smtp-Source: AOwi7QDZdYZsG/tx/S7aoMKr1ekynhRqHPV2kQQpW2mB9FwHmgNHIj/xk7pu872tIcWZRmbWNd6xAwbBpzLQO12a/jo= MIME-Version: 1.0 In-Reply-To: <20170913121628.GB11820@lunn.ch> References: <1505287939-14106-1-git-send-email-allen.lkml@gmail.com> <1505287939-14106-6-git-send-email-allen.lkml@gmail.com> <20170913121628.GB11820@lunn.ch> From: Allen Date: Wed, 20 Sep 2017 12:20:08 +0530 Message-ID: Subject: Re: [PATCH 06/10] drivers:ethernet: return -ENOMEM on allocation failure. To: Andrew Lunn Cc: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > static int cas_alloc_rxds(struct cas *cp) > { > int i; > > for (i = 0; i < N_RX_DESC_RINGS; i++) { > if (cas_alloc_rx_desc(cp, i) < 0) { > cas_free_rxds(cp); > return -1; > } > } > return 0; > } > > Again, your change is correct, but in the end the value is not used. > And if you fix it at the cas_alloc_rxds level, you also need a fix at > the next level up: > > err = -ENOMEM; > if (cas_tx_tiny_alloc(cp) < 0) > goto err_unlock; > > /* alloc rx descriptors */ > if (cas_alloc_rxds(cp) < 0) > goto err_tx_tiny; > > again, the return value is discarded. Andrew, How about the below patch as a fix? diff --git a/drivers/net/ethernet/sun/cassini.c b/drivers/net/ethernet/sun/cassini.c index 382993c..a88552c 100644 --- a/drivers/net/ethernet/sun/cassini.c +++ b/drivers/net/ethernet/sun/cassini.c @@ -3984,19 +3984,20 @@ static inline int cas_alloc_rx_desc(struct cas *cp, int ring) size = RX_DESC_RINGN_SIZE(ring); for (i = 0; i < size; i++) { if ((page[i] = cas_page_alloc(cp, GFP_KERNEL)) == NULL) - return -1; + return -ENOMEM; } return 0; } static int cas_alloc_rxds(struct cas *cp) { - int i; + int i, ret; for (i = 0; i < N_RX_DESC_RINGS; i++) { - if (cas_alloc_rx_desc(cp, i) < 0) { + ret = cas_alloc_rx_desc(cp, i); + if (ret < 0) { cas_free_rxds(cp); - return -1; + return ret; } } return 0; @@ -4241,7 +4242,7 @@ static int cas_tx_tiny_alloc(struct cas *cp) static int cas_open(struct net_device *dev) { struct cas *cp = netdev_priv(dev); - int hw_was_up, err; + int hw_was_up; unsigned long flags; mutex_lock(&cp->pm_mutex); @@ -4264,7 +4265,6 @@ static int cas_open(struct net_device *dev) cas_unlock_all_restore(cp, flags); } - err = -ENOMEM; if (cas_tx_tiny_alloc(cp) < 0) goto err_unlock; @@ -4309,7 +4309,7 @@ static int cas_open(struct net_device *dev) cas_tx_tiny_free(cp); err_unlock: mutex_unlock(&cp->pm_mutex); - return err; + return -ENOMEM; } static int cas_close(struct net_device *dev)