Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5494860pxv; Wed, 21 Jul 2021 06:56:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxGaCfdaPWWPI9mjSCLyn3lILnyc7qQutUBwtJMv7vsZhfxPs7ZogxteVNSuvbf0t1nJVr X-Received: by 2002:aa7:cc8e:: with SMTP id p14mr21511134edt.26.1626875819682; Wed, 21 Jul 2021 06:56:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626875819; cv=none; d=google.com; s=arc-20160816; b=srq1b09quqLaFgmleCI9OHT+QAnawQICBDzVbMfE/YyMbaP6KU7O8KGnRJUksueDW2 UgOCDgTciaNFKW7zqFlGqu+NbXDMwJ9OvocXr3d7z2k5uHKhvij1jSLWFj+3+8rTqqbg c7ODw6PXct+ZyWl5/Q5RFh+v0VU/aCdyFoUCwfxe3+FPWlAQAGXmeUm7blKnSOEfA3jx RK0iacvh+gShFn+UkANK9lYwLgfGhfiQyflkVXXSvqxruGm2/oyg1OJXx/a4QZ67I3Yc 8hqVWDyt1PBduE2wg2TyQvqp2LK36qo6FL+/eS6B7tDqvtUGPuaDDMHXE0ugof3cThbZ Jxcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=McA0Uja4aTo5CkkDEyBHkg5RwRFi2yTxWy1fIC6vUcc=; b=rZiDlgZ6y2FFHxmntndNyQPzLgkMIK1W1nIx9+dnbuiqFqvqN13A2WSUD4T2VZOF+2 2cXY6Cz3ND2DJKpiQ6BPy1FANeo8dGed/Ixwd8SRwz3XonHh3MABNdkkWRlJNlMizXK/ tpLja/loGaJqckWY4pEOajgzBBhhWuZYkdVOqlSYIz2UISutB0WRzOK7YbGSksrkXk9g 274TrmxjfcmUDEOfrv6EpG5Pg81XKPmEe5E2keRs6NdBJKNK6hoEgXYjpVry1HCpyeyN djJPSM6rN7tt/TBEq9k1yVJA0cxLYNv+eo8ooLby1pCFDIPcLchNJqrf00JmugkjKJS/ qkTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JG0D/Mcu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bl2si21082963ejb.55.2021.07.21.06.56.35; Wed, 21 Jul 2021 06:56:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JG0D/Mcu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233343AbhGUL7Q (ORCPT + 99 others); Wed, 21 Jul 2021 07:59:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:51550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235330AbhGUL7M (ORCPT ); Wed, 21 Jul 2021 07:59:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B34496120C; Wed, 21 Jul 2021 12:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626871189; bh=k+dVNJh5z43KdObG8GTDGe49OrDPmvX8GDjb/agtr2M=; h=From:To:Cc:Subject:Date:From; b=JG0D/McuaXACyq1qjGXq+xJ+Ejywo0LeSvNeSckTJEUnua5hkhC2r5xS7L912dtc6 NPWWv9jvlGDU1tvkZRWsjXqVIipvNe6EQAzTTrwZpcm40gPpyefA/Znxng0Yulnpdv Nt2CKHGRxEgJQ0ovqRgL/wzmZMtYQXP74YmJ0upmObFhJoQfAlsN9vHZfvuBirfCNj jdDvCmBlmQr5Kz0K942tfHN6hiUkpq1ArouhkpAce1au6ev9kTjrmkg9Mz+akLRLlq zgd9WORikcOJOvauU/R7DGehHY3ayJfXt7R4o/GsdF2fCKRT38K0xqr4uoFjB6JG6j 4oI6/sE1gYwPg== From: Leon Romanovsky To: "David S. Miller" , Jakub Kicinski , Shannon Nelson Cc: Leon Romanovsky , drivers@pensando.io, linux-kernel@vger.kernel.org, Moshe Shemesh , netdev@vger.kernel.org Subject: [PATCH net-next] ionic: cleanly release devlink instance Date: Wed, 21 Jul 2021 15:39:44 +0300 Message-Id: <956213a5c415c30e7e9f9c20bb50bc5b50ba4d18.1626870761.git.leonro@nvidia.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky The failure to register devlink will leave the system with dangled devlink resource, which is not cleaned if devlink_port_register() fails. In order to remove access to ".registered" field of struct devlink_port, require both devlink_register and devlink_port_register to success and check it through device pointer. Fixes: fbfb8031533c ("ionic: Add hardware init and device commands") Reviewed-by: Moshe Shemesh Signed-off-by: Leon Romanovsky --- Future series will remove .registered field from the devlink. --- .../net/ethernet/pensando/ionic/ionic_devlink.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c index b41301a5b0df..cd520e4c5522 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c @@ -91,20 +91,20 @@ int ionic_devlink_register(struct ionic *ionic) attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; devlink_port_attrs_set(&ionic->dl_port, &attrs); err = devlink_port_register(dl, &ionic->dl_port, 0); - if (err) + if (err) { dev_err(ionic->dev, "devlink_port_register failed: %d\n", err); - else - devlink_port_type_eth_set(&ionic->dl_port, - ionic->lif->netdev); + devlink_unregister(dl); + return err; + } - return err; + devlink_port_type_eth_set(&ionic->dl_port, ionic->lif->netdev); + return 0; } void ionic_devlink_unregister(struct ionic *ionic) { struct devlink *dl = priv_to_devlink(ionic); - if (ionic->dl_port.registered) - devlink_port_unregister(&ionic->dl_port); + devlink_port_unregister(&ionic->dl_port); devlink_unregister(dl); } -- 2.31.1