Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1645755imu; Wed, 23 Jan 2019 22:37:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN6QamRf1v+f4vnbFpbbKWMiO81575YkYxT/3DTAxzH7oENCuPZWAsSkMnV1q6hzacXWZEMK X-Received: by 2002:a17:902:8d8e:: with SMTP id v14mr5298860plo.133.1548311834684; Wed, 23 Jan 2019 22:37:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548311834; cv=none; d=google.com; s=arc-20160816; b=kP4xomL/hVcbQPkRqb93+NJ+Tj6rM/kDtElQSf01LxEbMMUyWc2jBlNzIQv7MjWUcI famtktEkfyyd/WS8EsbhL2abdLmoQp4lYV1tOcdohje6Zd5s+a5xKMQvzR0f17O88IxX pdoajufsu4ElLWYurtnCuea6b6HYt0Gp2e7EYXLGoDJPe5WuZ/j5EEhMerEt4M+lrt9+ d824QghR5nDJUFybr1xUDVpPl4TL+KwpuswYlb4HqeDlWw5Zxw5me2b4qr0fZ9BvO4iY C3G5LiZ4iXpmbQYPmdc4uZesJ7zte+X8r9UqX2/3lAZt18ZMKq3JUnTBHmdGxtkdMq3Y suhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=kho+gD1EsdrQf5jWVJBtKgxpUrWxq0DUaYFuyaIqJGE=; b=p1KHSUkat0LsX4IAvxGJ3HUXVMGyE5IKOVZwalBOl92V0xmTPjj1rShiYfrmuSV0In ugSYhd0jB/YsBJilnraJXyKy8hyuEVbVgVK4gXvYY0H5apdrJgO+v1OrzQPoCycWr6XM B3fcl3d51l//0+HeBvMa5sBR+TjyxOHglua2Fj/0gTjLaiDxccOZi8Z87hGk2DVAWD8t vNbMqKGZNOR+MTIF8JmwWqUypjUjbKcu5p7FspW36ygSUJ2nRRp6IU0G3/qcU9vA+CG8 qOcQBEEkoztlCea9ysEWPUiaR54qLMTpBdqEAaWGpxEKk+UH1wKA/N3ECOnWRcy1C44Y dl5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=D+XgDzTe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a26si21237352pgl.282.2019.01.23.22.36.59; Wed, 23 Jan 2019 22:37:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=D+XgDzTe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726405AbfAXGe5 (ORCPT + 99 others); Thu, 24 Jan 2019 01:34:57 -0500 Received: from mail.andi.de1.cc ([85.214.239.24]:48660 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbfAXGez (ORCPT ); Thu, 24 Jan 2019 01:34:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kho+gD1EsdrQf5jWVJBtKgxpUrWxq0DUaYFuyaIqJGE=; b=D+XgDzTeTs2PvrOqB34MeQPJR rk3M0nTixm4ZCcRDiit3/+ddEV8icfR6pTU0h/hvQa6xe005/lVuWa8WWuBq4tHByhyCnY3QA/bMN H7oM5H+l2thrury3Uuy0XkrfTGn2piiyhIMthDVnp9hqqkJRojITXQ9XeYeoOVQeTcoaQ=; Received: from [77.247.85.78] (helo=localhost) by h2641619.stratoserver.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gmYbB-0000vI-8Y; Thu, 24 Jan 2019 07:34:49 +0100 Received: from andi by localhost with local (Exim 4.89) (envelope-from ) id 1gmYb5-0007rN-Hi; Thu, 24 Jan 2019 07:34:43 +0100 From: Andreas Kemnade To: letux-kernel@openphoenux.org, johan@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andreas Kemnade Subject: [PATCH v4 1/5] gnss: sirf: write data to gnss only when the gnss device is open Date: Thu, 24 Jan 2019 07:34:35 +0100 Message-Id: <20190124063439.29897-2-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190124063439.29897-1-andreas@kemnade.info> References: <20190124063439.29897-1-andreas@kemnade.info> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The api forbids writing data there otherwise. Prepare for the serdev_open()/close() being a part of sirf_set_active. Signed-off-by: Andreas Kemnade --- No changes in v4 Changes in v3: - add more locking - style cleanup - mutex *not* renamed since we need a second one Changes in v2: - add locking drivers/gnss/sirf.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/gnss/sirf.c b/drivers/gnss/sirf.c index 59cde7e923b8..49bc021325e9 100644 --- a/drivers/gnss/sirf.c +++ b/drivers/gnss/sirf.c @@ -35,6 +35,10 @@ struct sirf_data { struct gpio_desc *wakeup; int irq; bool active; + + struct mutex gdev_mutex; + bool open; + wait_queue_head_t power_wait; }; @@ -44,9 +48,18 @@ static int sirf_open(struct gnss_device *gdev) struct serdev_device *serdev = data->serdev; int ret; + mutex_lock(&data->gdev_mutex); + data->open = true; + mutex_unlock(&data->gdev_mutex); + ret = serdev_device_open(serdev); - if (ret) + if (ret) { + mutex_lock(&data->gdev_mutex); + data->open = false; + mutex_unlock(&data->gdev_mutex); return ret; + } + serdev_device_set_baudrate(serdev, data->speed); serdev_device_set_flow_control(serdev, false); @@ -63,6 +76,10 @@ static int sirf_open(struct gnss_device *gdev) err_close: serdev_device_close(serdev); + mutex_lock(&data->gdev_mutex); + data->open = false; + mutex_unlock(&data->gdev_mutex); + return ret; } @@ -74,6 +91,10 @@ static void sirf_close(struct gnss_device *gdev) serdev_device_close(serdev); pm_runtime_put(&serdev->dev); + + mutex_lock(&data->gdev_mutex); + data->open = false; + mutex_unlock(&data->gdev_mutex); } static int sirf_write_raw(struct gnss_device *gdev, const unsigned char *buf, @@ -105,8 +126,14 @@ static int sirf_receive_buf(struct serdev_device *serdev, { struct sirf_data *data = serdev_device_get_drvdata(serdev); struct gnss_device *gdev = data->gdev; + int ret = 0; - return gnss_insert_raw(gdev, buf, count); + mutex_lock(&data->gdev_mutex); + if (data->open) + ret = gnss_insert_raw(gdev, buf, count); + mutex_unlock(&data->gdev_mutex); + + return ret; } static const struct serdev_device_ops sirf_serdev_ops = { @@ -275,6 +302,7 @@ static int sirf_probe(struct serdev_device *serdev) data->serdev = serdev; data->gdev = gdev; + mutex_init(&data->gdev_mutex); init_waitqueue_head(&data->power_wait); serdev_device_set_drvdata(serdev, data); -- 2.11.0