From patchwork Tue Nov 15 18:21:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Fulghum X-Patchwork-Id: 20499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2877549wru; Tue, 15 Nov 2022 10:21:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf71H7lP+CpOuFQXr3U0Jt/mwSiLYVICN6m8Fi9JiUl/wRYQ/nn8t5U2wR0AWyjdg3lqFyD2 X-Received: by 2002:a17:902:7283:b0:186:6f97:fe90 with SMTP id d3-20020a170902728300b001866f97fe90mr5265542pll.75.1668536514055; Tue, 15 Nov 2022 10:21:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668536514; cv=none; d=google.com; s=arc-20160816; b=HvGg1jH70pSCiCqdvSoujKrnb1sBiUJNdsvmK+jrbdvpAuKqvzK8YhfpA5G1gKLGUW u3OfLogZtnaqm3E0YWDjT4za+3u0qU2FpIiASyVcyghTFjKw7qAKBaSfqyU4s46hP1vH tijS578iRlKlXLUMknyxA5+f2J66/HaaFwkYCHgaNt/U6WLPYDs4R7TPHdcFxaF2CYQX yoE7m6gzOEHx84OaicFyGo2W8K5HOxJRvnEz7nFPoR9rYY39NhbUX+CJEtBZTrXqoIvm KN4vCdhG+obfJbbdDJ1ixVIR/vJTT9Kh6pyp2uXL1NJ7Wi1tC1vLgDuOwMEFe4yI65eF Thow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Pds9DPhUuKKKwvTuZXTljs6vTvJYl9KVSRCAhBrnBDU=; b=T1DI+ph7BzVDzhsJSgJcvnGK8nPY784jvW88cwIk4Y++B46o5+Qvw8/wGGUo5RSmof n/QR4gY1V1zUmJF8gS6LXJtFzMQYQPf+crgjwlKZlZdBmDzsUJqi3ln6WCMK/zDR1zJ9 Lb0KtzV2bNSzU/EEb+I+0pZ+gtP+b7cjDhKyVOqwN9wztVWAVpuQgMNVfmdTQ0cf99y3 K7W6qZkKKo6GroByPO314y2vKm53n5Blx2dKX47gKeu0Ap7lgj2iMo1fsEpOafvJav9O xr/4mklEQEeYMmEl1csxeXpbS8ntDXAjYKuzG/PPzMJPzMUFfrvb9hwrCwbQJ69wGqEZ RPpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microgate-com.20210112.gappssmtp.com header.s=20210112 header.b=XSJ48EZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a62e805000000b0053b9c18617esi12035447pfi.300.2022.11.15.10.21.38; Tue, 15 Nov 2022 10:21:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microgate-com.20210112.gappssmtp.com header.s=20210112 header.b=XSJ48EZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbiKOSVS (ORCPT + 99 others); Tue, 15 Nov 2022 13:21:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbiKOSVQ (ORCPT ); Tue, 15 Nov 2022 13:21:16 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED7E1740D for ; Tue, 15 Nov 2022 10:21:16 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so14620410pjk.1 for ; Tue, 15 Nov 2022 10:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microgate-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Pds9DPhUuKKKwvTuZXTljs6vTvJYl9KVSRCAhBrnBDU=; b=XSJ48EZAmzrhON5KIzsx1sxTghHHiJCpHMvI6da5Y5nBSDzfo73ldS4p01NFCUzgec Vvgu5l6g3X5QotkYlQnYyR4S8nBLUXi8edlKHPFwyeERuO9b8tvSJQnhUKAlK8GSuR7B z3vJOw05/rZXMsjPnNPX3fXmNCymQGoHGQTsZyJZzzrKyxftL0C/yJuE2UHg8c4uv27X eDANDl9Ibo9GBBKYU/Jtg7DMbFPzj89hlJcqHsW0WMK+wpNu6Vh8jVu525qdmSeBngma dzBFyQAFHggoGJzuxTEoG592l2fgy2UMhHAZrMi87CPDeM6ywa8EOgMr14jpRDtzZQPQ UvaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pds9DPhUuKKKwvTuZXTljs6vTvJYl9KVSRCAhBrnBDU=; b=DrgCx1k/RtIiYCgUyytvrQRsT5A0NEwm5Gv+4yxLxtzUY4KM85/iy1DDObGeRb18TM 2nQKD0b5GYkAPun69PkvulMkboWwLG5cAAf0R3lZuHnoww1FX7SUT6DL9EaGEV4J73tD CL7yPPs3SZBel/HP/PlB0R65gESpZOuVBLLWNhTGFQzjnfW6fvFq2NnvopSaoYV1FIUj Wy6Y9VjUJlRjTqiZ0EqOmUohHYv8TaPNYoGBuZA5KUVO0nscrebpY/aZvKrhIhW+Yhop /Hp+yRhpjBSUdQa9HQdHOppD5nHWs51M4hzdmEXQ/L5VWVEnjSkTvN3YUaiIBKsJOnnJ 6zTw== X-Gm-Message-State: ANoB5pkGrOtbiM7WSxN2re6e3+ETGd0Mij6u8R9Foo/9xnCR1uxZ82KT SQ379JWGn2FVD7OEkiGryOoGFA== X-Received: by 2002:a17:90b:3c11:b0:218:8f2:5af9 with SMTP id pb17-20020a17090b3c1100b0021808f25af9mr1749128pjb.65.1668536475613; Tue, 15 Nov 2022 10:21:15 -0800 (PST) Received: from [192.168.1.86] (c-208-53-111-167.customer.broadstripe.net. [208.53.111.167]) by smtp.gmail.com with ESMTPSA id y18-20020a17090a8b1200b0020d39ffe987sm8645310pjn.50.2022.11.15.10.21.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Nov 2022 10:21:15 -0800 (PST) Message-ID: <2b501d50-6777-a34f-7373-6648ed418794@microgate.com> Date: Tue, 15 Nov 2022 10:21:14 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: [PATCH] tty: synclink_gt: unwind actions in error path of net device open Content-Language: en-US To: Zhengchao Shao , linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: akpm@linux-foundation.org, weiyongjun1@huawei.com, yuehaibing@huawei.com References: <20221114010734.314910-1-shaozhengchao@huawei.com> From: Paul Fulghum In-Reply-To: <20221114010734.314910-1-shaozhengchao@huawei.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749582932793986465?= X-GMAIL-MSGID: =?utf-8?q?1749587343669167028?= hdlcdev_open() in synclink_gt.c did not fully unwind actions in the error path. The use of try_module_get()/module_put() is unnecessary, potentially hazardous and is removed. The synclink_gt driver is already pinned any point the net device is registered, a requirement for calling this entry point. The call hdlc_open() to init the generic HDLC layer is moved to after driver level init/checks and proper rollback of previous actions is added. This is a more sensible ordering as the most common error paths are at the driver level and the driver level rollbacks require less processing than hdlc_open()/hdlc_close(). This has been tested with supported hardware. Suggested-by: Zhengchao Shao Signed-off-by: Paul Fulghum diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c index 25e9befdda3a..72b76cdde534 100644 --- a/drivers/tty/synclink_gt.c +++ b/drivers/tty/synclink_gt.c @@ -1433,16 +1433,8 @@ static int hdlcdev_open(struct net_device *dev) int rc; unsigned long flags; - if (!try_module_get(THIS_MODULE)) - return -EBUSY; - DBGINFO(("%s hdlcdev_open\n", dev->name)); - /* generic HDLC layer open processing */ - rc = hdlc_open(dev); - if (rc) - return rc; - /* arbitrate between network and tty opens */ spin_lock_irqsave(&info->netlock, flags); if (info->port.count != 0 || info->netcount != 0) { @@ -1461,6 +1453,16 @@ static int hdlcdev_open(struct net_device *dev) return rc; } + /* generic HDLC layer open processing */ + rc = hdlc_open(dev); + if (rc) { + shutdown(info); + spin_lock_irqsave(&info->netlock, flags); + info->netcount = 0; + spin_unlock_irqrestore(&info->netlock, flags); + return rc; + } + /* assert RTS and DTR, apply hardware settings */ info->signals |= SerialSignal_RTS | SerialSignal_DTR; program_hw(info); @@ -1506,7 +1508,6 @@ static int hdlcdev_close(struct net_device *dev) info->netcount=0; spin_unlock_irqrestore(&info->netlock, flags); - module_put(THIS_MODULE); return 0; }