From patchwork Thu Apr 22 09:43:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 425854 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp189222jao; Thu, 22 Apr 2021 02:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlEhQ46slLejzA9aUi53GxlpIpfJ0GGwS+kNEXbKQVc3L4PUyMl1e+3t2305/JC8w5vJtV X-Received: by 2002:a62:4e4b:0:b029:25c:5e49:93bf with SMTP id c72-20020a624e4b0000b029025c5e4993bfmr2467625pfb.69.1619084080258; Thu, 22 Apr 2021 02:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619084080; cv=none; d=google.com; s=arc-20160816; b=grJWlfinqPxnv6EpsD4RLCcA489PIfQijXNFSXVf8pKPhWN4DAAZb6XceKOUYXvlmC nelyAFXw3e2gJD6RCq82zWWL78lAT0ZO3U/hSJZIW35SqWDVc9AfEy8oPNO9GkutkFuX NrGapAH1o9S4ys5pSAuxKeF1xHnNbyaQ8uvGJXErajcUXzOo2Gnt3WpSC/0Uhn0YM9mM eZ+juM5xQ1dXS8EkF1LdHM0ji8kml466c/mEYAhmvPV7aCP2qIfzTauLETOJ0E5e8Gid uQTxkCx4bFbzrh/VzCSZqxoiOoRXK5D6nnzricG4S52ZXIhuKEyTR9U6j8zblJffv14V KGLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=KbK/rt/VL2w8jSHm46KzCJTJMHDRS8TBwcrZdxvlZQk=; b=Pf9xicAwwuP9fsNCgmRzM/SLP0WDY47QnXts9nGSRTiKZpfWL+EElNZI3I1aPx38rm 7Dzz7GDp1bCcLYN7KktZaQa2hq9SLli0S7OBRFFYptkyOXqhUPs2xwfTutmE6cVzKeLV oJzLQI3f4/8mWsz0HxQawhermBrYG0W9Rk27dcXGMy5EHqsCpbYarrk+fPwyiuMTGuwg TOUPmZ9BVzFHOcyxV3j6Xrm9/3oLBhFVCQhcyTCiNdz8HH55Dg3/JUaadUoZN8BwdxlE vblKFNhsAs8eH8FVfkuMuWgUpgivHfnbHdHek0FndgqaTr54VD0ki+uSLnhthVK4wmbU cNuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LJzsD8rr; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hk2si5767129pjb.44.2021.04.22.02.34.40; Thu, 22 Apr 2021 02:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=@linaro.org header.s=google header.b=LJzsD8rr; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235553AbhDVJfA (ORCPT + 8 others); Thu, 22 Apr 2021 05:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235339AbhDVJez (ORCPT ); Thu, 22 Apr 2021 05:34:55 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D160C06174A for ; Thu, 22 Apr 2021 02:34:21 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id c15so35135623wro.13 for ; Thu, 22 Apr 2021 02:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=KbK/rt/VL2w8jSHm46KzCJTJMHDRS8TBwcrZdxvlZQk=; b=LJzsD8rrIQwYziKgRjIh2WPNfwfnaR9vtuJJZLFoc4+EikTpRSLEZjr1KCaeFj8Mcf VMgyAXFEYkA8Bt9PuE9v1XLzbpz7odFa/mNLaW5ZSUn/BRqyrgZG7b4yQI2x+k6qgMeO ZMqIkYpnN2UT7rfjJOxRAH158x4Wn7WkSFRsu8FF8T/qZ9sGKmEhrelaAb1tuuA4omnH v5neocraSTjTEaY1J4niMLgPEJX0YJhuMYF18PjBrspF8i9N2Zi7OSgxxSJduZjxMODi nSUvtCwVl5bT+g3hZpwABG63eAP7qpxDRtufw8gdLRf/DpaXBIzomEg7337phB+JHPHe ++6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KbK/rt/VL2w8jSHm46KzCJTJMHDRS8TBwcrZdxvlZQk=; b=PlHSoxn4PHRQI/PzP8E8ZRU5YXePANJUJSVMZcb+gPfjcOK5HbkFn6CpuL/MiRjUIk M5oveiwqxzIChkuKrufoQScN0f5cROa5+Swphrw3/7p50m5nUExpc/zXyjQegdQl6Iks k8B/L4IBoXojpM15JlRDWAesfwlrhpCZqTPA/o4oDJFI2BAXL6QMoy30UbYexNYvQL6L IcIS9QOH/jfbkGLIsrcIaeaHAW/UwPr4LZ2JAXwhMUD2N3i0Dv8YU3wfCDatt4vzqSDv ojmKzV9K0hzOvv3tthb4YMuB8Qd8UNn7uImFS7ABkr84g2G+8jm00Jvc39bsibEQycH9 0SrQ== X-Gm-Message-State: AOAM532GyuCOAjZwDpSO96aOPq/BtjKs1dfuUqI5hnJGt93/9fpj2syP NCzyOXSCv6dFMy07NYghSVa+lt69BcJJ2Tqt X-Received: by 2002:a5d:43c1:: with SMTP id v1mr2932089wrr.419.1619084059857; Thu, 22 Apr 2021 02:34:19 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:d197:cfbe:5a91:301]) by smtp.gmail.com with ESMTPSA id h81sm2717519wmf.41.2021.04.22.02.34.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Apr 2021 02:34:19 -0700 (PDT) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, Loic Poulain Subject: [PATCH net-next] net: wwan: core: Return poll error in case of port removal Date: Thu, 22 Apr 2021 11:43:34 +0200 Message-Id: <1619084614-24925-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Ensure that the poll system call returns error flags when port is removed, allowing user side to properly fail, without trying read or write. Port removal leads to nullified port operations, add a is_port_connected() helper to safely check the status. Fixes: 9a44c1cc6388 ("net: Add a WWAN subsystem") Signed-off-by: Loic Poulain --- drivers/net/wwan/wwan_core.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 5be5e1e..c965b21 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -369,14 +369,25 @@ static int wwan_port_op_tx(struct wwan_port *port, struct sk_buff *skb) return ret; } +static bool is_port_connected(struct wwan_port *port) +{ + bool connected; + + mutex_lock(&port->ops_lock); + connected = !!port->ops; + mutex_unlock(&port->ops_lock); + + return connected; +} + static bool is_read_blocked(struct wwan_port *port) { - return skb_queue_empty(&port->rxq) && port->ops; + return skb_queue_empty(&port->rxq) && is_port_connected(port); } static bool is_write_blocked(struct wwan_port *port) { - return test_bit(WWAN_PORT_TX_OFF, &port->flags) && port->ops; + return test_bit(WWAN_PORT_TX_OFF, &port->flags) && is_port_connected(port); } static int wwan_wait_rx(struct wwan_port *port, bool nonblock) @@ -508,6 +519,8 @@ static __poll_t wwan_port_fops_poll(struct file *filp, poll_table *wait) mask |= EPOLLOUT | EPOLLWRNORM; if (!is_read_blocked(port)) mask |= EPOLLIN | EPOLLRDNORM; + if (!is_port_connected(port)) + mask |= EPOLLHUP | EPOLLERR; return mask; }