netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: wwan: core: Return poll error in case of port removal
Date: Thu, 22 Apr 2021 13:49:32 +0300	[thread overview]
Message-ID: <YIFUvMCCivi62Rb4@unreal> (raw)
In-Reply-To: <1619084614-24925-1-git-send-email-loic.poulain@linaro.org>

On Thu, Apr 22, 2021 at 11:43:34AM +0200, Loic Poulain wrote:
> 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 <loic.poulain@linaro.org>
> ---
>  drivers/net/wwan/wwan_core.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> 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;
> +}

The above can't be correct. What prevents to change the status of
port->ops right before or after your mutex_lock/mutex_unlock?

> +
>  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;
>  }
> -- 
> 2.7.4
> 

  reply	other threads:[~2021-04-22 10:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22  9:43 [PATCH net-next] net: wwan: core: Return poll error in case of port removal Loic Poulain
2021-04-22 10:49 ` Leon Romanovsky [this message]
2021-04-22 11:21   ` Loic Poulain
2021-04-22 12:59     ` Leon Romanovsky
2021-04-22 13:37       ` Loic Poulain
2021-04-22 14:56         ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIFUvMCCivi62Rb4@unreal \
    --to=leon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).