Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1342019ybk; Sat, 16 May 2020 08:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWzS2eZXFostXJk5gVNIo8XLez6tssWsOijyXk7BRQx+WxjaUgNcqNILv7odOyQXJFUk+y X-Received: by 2002:a50:8b06:: with SMTP id l6mr6902154edl.190.1589642239940; Sat, 16 May 2020 08:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589642239; cv=none; d=google.com; s=arc-20160816; b=lRflaPSNtx/r1qBeNHU0W+E7EagqvshromX8MKHwQOStSQL7ZgEVWdWo4uI8XoPmGk 0E9qlRi8uo1B/3R/BCyMdCtf8BEY5caNYCQxKzwBHVEE5DyIpXRWQVp1Vb7gV9HqyxAo qj/2ifk8xoxTBL+qs2iEAWSR3EVLK5oyrYNh31m1wdXccykij/+CaUehxqXx6+na69Cp mJTChQCeUnA2NHiyI76YufT5owU2ogrd6uw0++vCjC++HsUSJEYahoPBQnQrSzHASyw3 PkwOD0P3JAwG2dY8mUpbLhYAPxPYBj/YUpUORiZ89vix7h5Y75N1yW6qUrGwTSIIoL3j ck7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=TcKdqZP/r7DUE6bv+icT2eVQYXmaXRuMmmHecFCE7b0=; b=ZW43+jQrqXJH781TMEHhiL1cQUuSd8KyxKQCryNA5/I89VqpZROduat1jKDv04jwp6 V5AJriucRSNylNpKnrm4Sf2yYVzJLwlqPDvR7CFs5swKQqwy6IM2RihxUw8fH92QJg8z 785L5GtgDI3SfqT9ucAC/OPvSGCgzCXB8r5LVQaWh29HpXPqGgHoPaXoyix8DsbkALgw wBKpZ1aglYS0NVzcoYS/Ebz5Hv9++xJEDOvXowsAIJctUQ3+oVOyKb6NxJVObUsn2MTP 1XufYi6/YAZF6bSnzrSL/MndaurXjJw3POXtYQH3b28Qu4IPvNVKcAanmEWCEnSu43Kw iw3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FZ3yi1Bw; 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 96si412843edq.298.2020.05.16.08.16.52; Sat, 16 May 2020 08:17:19 -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=default header.b=FZ3yi1Bw; 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 S1726967AbgEPPPa (ORCPT + 99 others); Sat, 16 May 2020 11:15:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:59388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbgEPPP3 (ORCPT ); Sat, 16 May 2020 11:15:29 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01277206F4; Sat, 16 May 2020 15:15:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589642129; bh=TvYmaQ8eMDWoMjGeOehMDYvi6OnPvQT2KhChiMq4ok8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FZ3yi1BwxUsykmQErmmXwqTLW/ZNxAk8WNI91vX7WEG8VLYS2DBPEyuPHAAcTtwvh YtJkiZfSitF0HvmmQRkSgebnfFbbGhas54gr/qCeY2n4k3IdUi24wQQetg7X2xx72+ LKO2ICfxcZpeT4VaakE3nTWcVWDdwkX4LoMeFjyU= Date: Sat, 16 May 2020 16:15:24 +0100 From: Jonathan Cameron To: Sergiu Cuciurean Cc: , , Lars-Peter Clausen , Michael Hennerich , "Stefan Popa" , "Hartmut Knaack" , Peter Meerwald-Stadler Subject: Re: [PATCH] iio: dac: ad5360: Replace indio_dev->mlock with own device lock Message-ID: <20200516161524.06266b79@archlinux> In-Reply-To: <20200514083921.51966-1-sergiu.cuciurean@analog.com> References: <20200514083921.51966-1-sergiu.cuciurean@analog.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 May 2020 11:39:19 +0300 Sergiu Cuciurean wrote: > As part of the general cleanup of indio_dev->mlock, this change replaces > it with a local lock on the device's state structure. > This also changes some internal functions to pass the pointer to the > state-struct vs a ref to indio_dev just to access the state-struct again. > > Signed-off-by: Sergiu Cuciurean Applied. Thanks, Jonathan > --- > drivers/iio/dac/ad5360.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c > index 2ac428b957e3..3e0c9e84e8da 100644 > --- a/drivers/iio/dac/ad5360.c > +++ b/drivers/iio/dac/ad5360.c > @@ -67,6 +67,7 @@ struct ad5360_chip_info { > * @chip_info: chip model specific constants, available modes etc > * @vref_reg: vref supply regulators > * @ctrl: control register cache > + * @lock lock to protect the data buffer during SPI ops > * @data: spi transfer buffers > */ > > @@ -75,6 +76,7 @@ struct ad5360_state { > const struct ad5360_chip_info *chip_info; > struct regulator_bulk_data vref_reg[3]; > unsigned int ctrl; > + struct mutex lock; > > /* > * DMA (thus cache coherency maintenance) requires the > @@ -205,10 +207,11 @@ static int ad5360_write(struct iio_dev *indio_dev, unsigned int cmd, > unsigned int addr, unsigned int val, unsigned int shift) > { > int ret; > + struct ad5360_state *st = iio_priv(indio_dev); > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > ret = ad5360_write_unlocked(indio_dev, cmd, addr, val, shift); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > > return ret; > } > @@ -229,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, > }, > }; > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > > st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | > AD5360_ADDR(AD5360_REG_SF_READBACK) | > @@ -240,7 +243,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, > if (ret >= 0) > ret = be32_to_cpu(st->data[1].d32) & 0xffff; > > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > > return ret; > } > @@ -261,7 +264,7 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set, > struct ad5360_state *st = iio_priv(indio_dev); > unsigned int ret; > > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&st->lock); > > st->ctrl |= set; > st->ctrl &= ~clr; > @@ -269,7 +272,7 @@ static int ad5360_update_ctrl(struct iio_dev *indio_dev, unsigned int set, > ret = ad5360_write_unlocked(indio_dev, AD5360_CMD_SPECIAL_FUNCTION, > AD5360_REG_SF_CTRL, st->ctrl, 0); > > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&st->lock); > > return ret; > } > @@ -479,6 +482,8 @@ static int ad5360_probe(struct spi_device *spi) > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->num_channels = st->chip_info->num_channels; > > + mutex_init(&st->lock); > + > ret = ad5360_alloc_channels(indio_dev); > if (ret) { > dev_err(&spi->dev, "Failed to allocate channel spec: %d\n", ret);