From patchwork Thu Oct 3 17:34:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821305 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB319DDCD; Thu, 3 Oct 2024 17:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976883; cv=none; b=DEwzwJUn35ORAkawKuy7jXjEdCUjEea3eyiRD4an8lIYRwHz5npYoxyY5ON0uOB9nGyFx736vLw8Nc+QoUXINkB/aooeZqZedQ/J4eTYoa3HveK7c4TY8bYoOUdBmiJFMFjqgXdtBRxdBb5joy2gjUGA8+tJJ5imrxJx7guE0gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976883; c=relaxed/simple; bh=7Qd7pConDOask/BNXfSwFweuyl/4yUcBzrozpeWuKdI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kVpjlhRUWJkALOC+hoHIWlGk7lEXcw1FlW9MYbscvBDvACWgfgUXUJn6Dz8kVFkxq+BSu1YJO0PoTZBuIteW31tKPkI0kLvNnftFGPrRhcR/0gfpJ4fSVcunxtS8zmap7EC+KZzj8C/QxRv24qstHKVvTbjrJnnRfJjYZaRaw94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JYqgIQXD; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JYqgIQXD" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-37cdac05af9so1230343f8f.0; Thu, 03 Oct 2024 10:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976880; x=1728581680; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7h4jXiLdPt0pxESQJDinZHqz2wgnSDllGc714nCDCUQ=; b=JYqgIQXD/dm7Ev17zIlhiN1ndAimGrDGY3PlkeCcJ6S6Ehlkc14H0hVks6Ub8hFjfd P+sE66659uf0CDTtWTP+iPz+Ja1ftDwAtkxVaGRqcmmYGK5s23R5mfDBhpemFiNNcJrX dha2MnGQHvwF9Ri5M56dudqWAdXXO9HpbJTYMmQKrgjd0dnQ4Al470HBAjJFmDC1U8up tIil0Th7qK1kwvylhjpa1q0I0GR2KVxeJvl9e5DzbPbtnrdrtPCc+XH2yVHzkZr0OUCT 2R+o7JLgmh9LMsuRyupekeyNMtdkXHRX9loz+kYbueSlwnvFLEIy6zZnGjuZFY85xtmR mjvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976880; x=1728581680; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7h4jXiLdPt0pxESQJDinZHqz2wgnSDllGc714nCDCUQ=; b=nt63h32qRmX5ZIYHFy01oEDQQ9uZatZfy4Z9JDsCm9feLpmamRPX5FeBRnHsN8OF6c BAZCp+7Tekb0DhHoflU3D0Yq7z2lgHPpC+OpAjFN31fm/ySl8r6Bxb91XwDgbosDZ39B /V2Qw2WlxVNaRQ1Do0ndDZGHjgDyr+0rdCpUjQyq0xqMLUZfXTYuqH69x3x2di6j2DA1 ADSqY9Z7E5cvdaCAPRv3xs3re1+i5PSvo0OIzUWoEGWObsUcLJx0HdOntkkfKWtaFFkh k/w1cZYkmr/z8z2UtgGkKCYOc4Hov8UVMjx/+UPOhkXTSCxlBJL4Zv/sHRJ1u8FmCYNm Ly1A== X-Forwarded-Encrypted: i=1; AJvYcCWjorGygToCaKDBbLqq77RLqXXITRj2adNs/hsSMEKHvJiQdTKyNUHrZHjQYILeFZw6XvuJvZRRsiY=@vger.kernel.org, AJvYcCXQbVNuG3lE0AZHWfPEc/xKO586/Q9qk0uqHpnYskzLLRpaSBiPQVfOSyofvFStWGYYhMRY1eRue7o5Fg==@vger.kernel.org, AJvYcCXhwcECNcC6YcolbVTILSKRk/Xvqxe180ozgh38HxDjO0mWWLb/mB3VPa9O/WWsMyTQgUFM5Bkiwy62r9E=@vger.kernel.org X-Gm-Message-State: AOJu0YyuvBr/Xdb1u4mnnOlVNRY15dbgJPTbUHObO/4ApH2n88NwSS5Z WRgyrtPEiYyOIutw4RNS0z3mJUDSox8FrwL4ND6GoML2Kvi++eIS X-Google-Smtp-Source: AGHT+IFYXJ4cT7wIRHX5Lvd/NZde12jGaUy1DpudCWiHF3jLCUVlAtvMN9LjEyoXYv6RhQtqt9n4Ng== X-Received: by 2002:adf:cd06:0:b0:37c:d270:e5cf with SMTP id ffacd0b85a97d-37d0e779b4emr111859f8f.33.1727976879849; Thu, 03 Oct 2024 10:34:39 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d081f7035sm1705056f8f.23.2024.10.03.10.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:39 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:06 +0200 Subject: [PATCH 1/7] iio: core: add read_avail_release_resource callback to fix race Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-1-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 Some iio drivers currently share an available info buffer that might be changed while iio core prints it to sysfs. To avoid the buffer corruption, add a release callback to let iio drivers allocate a copy of the available info buffer and later free it in the release callback. Such control is kept in the driver logic so that some driver that needs a big available info buffer might also perform some check to keep the copied buffer around in case no race has occurred. Signed-off-by: Matteo Martelli --- drivers/iio/industrialio-core.c | 14 +++++++++++--- include/linux/iio/iio.h | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 6a6568d4a2cb3a3f63381d5a6f25a2881b3ba2ed..4aea9de9f15a4d70f9d02fb3d47df49eef8c8423 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -859,12 +859,20 @@ static ssize_t iio_read_channel_info_avail(struct device *dev, return ret; switch (ret) { case IIO_AVAIL_LIST: - return iio_format_avail_list(buf, vals, type, length); + ret = iio_format_avail_list(buf, vals, type, length); + break; case IIO_AVAIL_RANGE: - return iio_format_avail_range(buf, vals, type); + ret = iio_format_avail_range(buf, vals, type); + break; default: - return -EINVAL; + ret = -EINVAL; } + + if (indio_dev->info->read_avail_release_resource) + indio_dev->info->read_avail_release_resource( + indio_dev, this_attr->c, vals, this_attr->address); + + return ret; } /** diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 18779b631e9071801958fc9d50b941b548fab940..55326f0310b2e9b3fa561c4728e7eabe1d7a5e78 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -491,6 +491,10 @@ struct iio_info { int *length, long mask); + void (*read_avail_release_resource)(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask); + int (*write_raw)(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, From patchwork Thu Oct 3 17:34:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821306 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9583C1AAE37; Thu, 3 Oct 2024 17:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976886; cv=none; b=urChykO8Len1hvmyuUJBJAHHImbHBVbQu2njr/81XZikeQpdV1uOAISUa9BzZQA59oA4qVrgoshRfCdruEEXy7kqoPPRV9yJc9g1c+f3uPPEMrjTCFF8K+VlKpDWB4wg0+IXejk7khESTpM+7kUwEi9ApSsrfazzSYZfNYBgPyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976886; c=relaxed/simple; bh=cNg176BYetOGo2MpF+NBbDgUNyJwivGqccecDk2ywTU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S6C0B0VvwqfBTdCJo6x1RbNJrntNy6KAJlEDrGe2DoHSTK5u12JFocXrmjaeb0ZA7gfGQiVe4ls4nQh6qjt71QzYDXP5TGYf+2YUmrTdI6McTG/1yCKnI/XjDw07aDjd50OFNgrn6QoebmTNibfKfa8a4yOFArHOvnvQn2FeS5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IaRETnWh; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IaRETnWh" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cd74c0d16so12261635e9.1; Thu, 03 Oct 2024 10:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976883; x=1728581683; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gYEu7vJAEzzRAf4hNdfGGtBas1po8e0YLUji+g4IAZE=; b=IaRETnWh+BMUXZcCFdAbtwdPtgEBswwTEwqU/DMuGFywJNhRduJdEBmdIMFgceTICg iqDHC8M1UqfOf7uaJ5ZCZ++sYZkGEfzgOnQI3iV+Te7+pT4Z31MF3m6C3TjHUc7WFvTv lAvO1pRMGu5+rA7KqePfm0GZzF8V6Zd0dTu3mpYYXaBdPGre4uZ+L0m2/7bda0daSC71 RfGXd4EU9Yi1kmvDzU3WVPxr5MVFyMyrkud4DC4N6LObZjq9PX1A75yniK/BFwcYGzJW srGXu8PuGGPji49dxopXMZi3zAfxWYkSSrun2mmC+IQg66ydsDCKJYPr3dlfmeqHba+l HufA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976883; x=1728581683; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gYEu7vJAEzzRAf4hNdfGGtBas1po8e0YLUji+g4IAZE=; b=eBvYTXQJI88TDI4qgOzEV5+nR7CP2HnzPhwGPlzCp8vUaYwNxgU1e2kB+uS84RI6gJ j8u6FAuDCh5opBzHYmo4RCn0fQXVw4cShv+lrl8VautlHPOVD+ChCNJTB6PhdYdjLNDZ SnqPrGIsk/euY3G/v6qIWBONJcy7xwP+5Zs6AieARdZ+5g0mARsdFxric30o+lZCW8ig et0dPJB3fH0h2cqONxEheU9Y0kAjCzrSk5JT6/5UzEN+DQVooAq8WfW0Mc11Vp3EYcVy 5XRMBKz5OHH8wpFTgIoia7gmwF+FiYYZY3gzPb+WXVWuORW0j+99bj1i9y+TpbKp7nTg UhKw== X-Forwarded-Encrypted: i=1; AJvYcCUz39CMTNXxEfIFHBFbgKhegTklAF3oXGKiipvQRRnEVyvCCRclO6WS3yvi6swxLPjbCKf5erhCu+tSHQ==@vger.kernel.org, AJvYcCWtk6tbr+shKXGBuJgpO8ely0TcdEaKm7ZkJK1ztx0eK/JZGwYflPQGOin7ko6L51ChkDj/ykZBycI=@vger.kernel.org, AJvYcCXEQM5ODlbtpFJvpN5YzF2p0xuxqxQkbCBdvctz1jKB3Cqut8/YJT6F6apbjZnMxtjbR5PoXJ2PtuIlEls=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7HS3CdfJ2HUkZQfJH6jGpVp8yDSTbn/nKwQ+68/d4emWpdX1P 9R/ouz/eMlPMXsmRPusnttxSAa3S/EFYw/aXJb+oED8oPWh+Q6tx X-Google-Smtp-Source: AGHT+IHTPFOFNPN3BeckBHKcogONqJyh8WuQeJEfQQzsuoj40NUYhsA6Ja/Wd7KXoljDjmnGp5wiHA== X-Received: by 2002:a05:600c:1551:b0:42c:ac9f:b528 with SMTP id 5b1f17b1804b1-42f778f5ba5mr51635555e9.35.1727976882600; Thu, 03 Oct 2024 10:34:42 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f79c67c5csm50718505e9.0.2024.10.03.10.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:41 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:07 +0200 Subject: [PATCH 2/7] iio: pac1921: use read_avail+release APIs instead of custom ext_info Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-2-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 The pac1921 driver was exposing the available scale info via an ad-hoc ext_info attribute instead of using the read_avail API. This to avoid a possible race condition: while the available current scales were being printed to sysfs by iio core (iio_read_channel_info_avail), the shunt resistor might have been changed concurrently. Switch to the read_avail+release APIs now that the race condition has been addressed. Signed-off-by: Matteo Martelli --- drivers/iio/adc/pac1921.c | 128 ++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 83 deletions(-) diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c index 4c2a1c07bc399028f0334885fc9cd4552d5892b1..f491a4923380ef9b406a68f8cc413df873869e3e 100644 --- a/drivers/iio/adc/pac1921.c +++ b/drivers/iio/adc/pac1921.c @@ -445,11 +445,52 @@ static int pac1921_read_avail(struct iio_dev *indio_dev, *vals = pac1921_int_num_samples; *length = ARRAY_SIZE(pac1921_int_num_samples); return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_SCALE: + switch (chan->channel) { + case PAC1921_CHAN_VBUS: + *vals = (const int *)pac1921_vbus_scales; + *length = ARRAY_SIZE(pac1921_vbus_scales) * 2; + *type = IIO_VAL_INT_PLUS_NANO; + return IIO_AVAIL_LIST; + + case PAC1921_CHAN_VSENSE: + *vals = (const int *)pac1921_vsense_scales; + *length = ARRAY_SIZE(pac1921_vsense_scales) * 2; + *type = IIO_VAL_INT_PLUS_NANO; + return IIO_AVAIL_LIST; + + case PAC1921_CHAN_CURRENT: { + struct pac1921_priv *priv = iio_priv(indio_dev); + + *length = ARRAY_SIZE(priv->current_scales) * 2; + *type = IIO_VAL_INT_PLUS_NANO; + + guard(mutex)(&priv->lock); + + *vals = kmemdup_array((int *)priv->current_scales, + *length, sizeof(int), GFP_KERNEL); + if (!*vals) + return -ENOMEM; + + return IIO_AVAIL_LIST; + } + default: + return -EINVAL; + } default: return -EINVAL; } } +static void pac1921_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + if (mask == IIO_CHAN_INFO_SCALE && + chan->channel == PAC1921_CHAN_CURRENT) + kfree(vals); +} + /* * Perform configuration update sequence: set the device into read state, then * write the config register and set the device back into integration state. @@ -749,6 +790,7 @@ static int pac1921_read_event_value(struct iio_dev *indio_dev, static const struct iio_info pac1921_iio = { .read_raw = pac1921_read_raw, .read_avail = pac1921_read_avail, + .read_avail_release_resource = pac1921_read_avail_release_res, .write_raw = pac1921_write_raw, .write_raw_get_fmt = pac1921_write_raw_get_fmt, .read_label = pac1921_read_label, @@ -806,88 +848,7 @@ static ssize_t pac1921_write_shunt_resistor(struct iio_dev *indio_dev, return len; } -/* - * Emit on sysfs the list of available scales contained in scales_tbl - * - * TODO:: this function can be replaced with iio_format_avail_list() if the - * latter will ever be exported. - * - * Must be called with lock held if the scales_tbl can change runtime (e.g. for - * the current scales table) - */ -static ssize_t pac1921_format_scale_avail(const int (*const scales_tbl)[2], - size_t size, char *buf) -{ - ssize_t len = 0; - - for (unsigned int i = 0; i < size; i++) { - if (i != 0) { - len += sysfs_emit_at(buf, len, " "); - if (len >= PAGE_SIZE) - return -EFBIG; - } - len += sysfs_emit_at(buf, len, "%d.%09d", scales_tbl[i][0], - scales_tbl[i][1]); - if (len >= PAGE_SIZE) - return -EFBIG; - } - - len += sysfs_emit_at(buf, len, "\n"); - return len; -} - -/* - * Read available scales for a specific channel - * - * NOTE: using extended info insted of iio.read_avail() because access to - * current scales must be locked as they depend on shunt resistor which may - * change runtime. Caller of iio.read_avail() would access the table unlocked - * instead. - */ -static ssize_t pac1921_read_scale_avail(struct iio_dev *indio_dev, - uintptr_t private, - const struct iio_chan_spec *chan, - char *buf) -{ - struct pac1921_priv *priv = iio_priv(indio_dev); - const int (*scales_tbl)[2]; - size_t size; - - switch (chan->channel) { - case PAC1921_CHAN_VBUS: - scales_tbl = pac1921_vbus_scales; - size = ARRAY_SIZE(pac1921_vbus_scales); - return pac1921_format_scale_avail(scales_tbl, size, buf); - - case PAC1921_CHAN_VSENSE: - scales_tbl = pac1921_vsense_scales; - size = ARRAY_SIZE(pac1921_vsense_scales); - return pac1921_format_scale_avail(scales_tbl, size, buf); - - case PAC1921_CHAN_CURRENT: { - guard(mutex)(&priv->lock); - scales_tbl = priv->current_scales; - size = ARRAY_SIZE(priv->current_scales); - return pac1921_format_scale_avail(scales_tbl, size, buf); - } - default: - return -EINVAL; - } -} - -#define PAC1921_EXT_INFO_SCALE_AVAIL { \ - .name = "scale_available", \ - .read = pac1921_read_scale_avail, \ - .shared = IIO_SEPARATE, \ -} - -static const struct iio_chan_spec_ext_info pac1921_ext_info_voltage[] = { - PAC1921_EXT_INFO_SCALE_AVAIL, - {} -}; - static const struct iio_chan_spec_ext_info pac1921_ext_info_current[] = { - PAC1921_EXT_INFO_SCALE_AVAIL, { .name = "shunt_resistor", .read = pac1921_read_shunt_resistor, @@ -911,6 +872,7 @@ static const struct iio_chan_spec pac1921_channels[] = { .type = IIO_VOLTAGE, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ), @@ -928,12 +890,12 @@ static const struct iio_chan_spec pac1921_channels[] = { .indexed = 1, .event_spec = pac1921_overflow_event, .num_event_specs = ARRAY_SIZE(pac1921_overflow_event), - .ext_info = pac1921_ext_info_voltage, }, { .type = IIO_VOLTAGE, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ), @@ -951,12 +913,12 @@ static const struct iio_chan_spec pac1921_channels[] = { .indexed = 1, .event_spec = pac1921_overflow_event, .num_event_specs = ARRAY_SIZE(pac1921_overflow_event), - .ext_info = pac1921_ext_info_voltage, }, { .type = IIO_CURRENT, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ), From patchwork Thu Oct 3 17:34:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821307 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7CC1AB53A; Thu, 3 Oct 2024 17:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976889; cv=none; b=mdEKsJdCWlUSzZ5kKB9n26MVa7KJjGGF2seqv8EYVMnUq1GC7jXbyy0MzHVt8bOTJGtjwD4H9T00Lp17fmy371SenAL/6KNByASNssUU2PWVtbTcdUFDjdayV1a6b1G/xSL5VaA/ZPhbMxm25vPZnDq9Qb5o9A4PEif2vR1KngE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976889; c=relaxed/simple; bh=2/hMSftv+3dvVX2Wa2Ap1k9j9lysmFSfimPuu4XRnro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JPRrCQl2KtYA9iKlqINxbdf7MTnoKQWiOTzagBosNrhVbnAElCowcSQvZoUSlGbyQuCY3v3kLAE/tqtWZFWJcS0gvoWdtFcOvg1l5KK+eXXh9VzdsTxrZDuqgtXh9mhLFGItqDNIIskXbP4c2q4hY367l/e/RgI8rgMUxMp4Ayg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MxGq9tQh; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MxGq9tQh" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso11706975e9.2; Thu, 03 Oct 2024 10:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976886; x=1728581686; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MTXdcjBlauvr7yxzI4HI4Dpu0RqCMP0lDL0VjxoSP1k=; b=MxGq9tQhXI+DrfmUcZVXhtSBWJY5fQgH8UBmUV7kPegnQcMRisLJIm/LZnj5t4WZB4 Xsrt+DLlfj6QkIXsACokxLLsVV2qlGO2NvKxHE1YaycS8MECBNeWOXLkyZLOcm5aY6Zt RbXVBeh87df6rhWZXglzoj+hs2EmZE8lZSTD1YdHKezrxnLqcXECWB3HG+VU+MAoSSGV YSSO3leL+si09yagwyXtZT1RYppI1uPCXmCAZKkUx89wBdFGEQYfwHhQn9j3//mTuy/u Uo2u52CgMsZyc9c71PA9QgzNb+fZgTRrGLJEomaRXq9/3KnM/+3JQa5Ep8FHCqhahHVh 8UfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976886; x=1728581686; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MTXdcjBlauvr7yxzI4HI4Dpu0RqCMP0lDL0VjxoSP1k=; b=ktjr0zDj2d/GhpZ/aiOZHedi0WeWM1kfVerVzprNE8bLWZWB9amNiIv8v3nyb/Ywy5 B9C39p3iVUh0SBk+4CTWaT3O/NSWyO7Q0b3YwLd1nx63dHnPH3RL6+s+mkdNg9ALxvJJ KXG+SG6+HZj+4ofoOgHkL7YAqLYYf9L82UIcy98tBvFceEBTHi2ReuahH5/fpzsHJ1GD D6H3IJ8bxspi/NCETcQlbqfihr0pIwzCRbEBtUclv6pIgnRPturfBX7vEZU/KrneR6Mm vAA6FiXEoc2edH46xFpMLZGFCvheVjq/52TpBAyVg5jaH9lDU9Uj9MHxfZkF/lL4N1Nt jVVQ== X-Forwarded-Encrypted: i=1; AJvYcCUqDLoxPAqgazf+LA+TahULT6Ns/dZvO8v4keJZMFJ+P4JgYha3j/v0sPL9zNl7QeGIAZ5Ggz5Fc/E=@vger.kernel.org, AJvYcCVLoEiLOaa5z7RWo+bp4aYFF8Pnxk4XSxStO6BkbTw628IhdJk2uLrBh55HMx2SumiD4Ire4APgPb+8E2k=@vger.kernel.org, AJvYcCXzZgLcPLmZ4JBPvHAl/gc4ZVZtVxZAYDhQcM766R9NxgTEZOvI16IYCzH8ztR3yRnyyPAK1vjcnrN71A==@vger.kernel.org X-Gm-Message-State: AOJu0YyIwMuPGsaeJnQqTos2wvKHpMDzZOJGWc6gf8x5t5I8Xg/bVnTF K7VcIJC32YxiFwsjEOa9KJn/011MFPWWqX/F/e+G1D1km1zqHfKw X-Google-Smtp-Source: AGHT+IHn6LdeRuDWE8fHAt/wjcTUVQYdBz6//TPcMWsGZOuJa319SrxzZL9LhUsa2CXPwqGuJroUHA== X-Received: by 2002:a05:600c:3b8a:b0:42c:b309:8d1a with SMTP id 5b1f17b1804b1-42f777bac51mr58068895e9.13.1727976885467; Thu, 03 Oct 2024 10:34:45 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b50bsm20382895e9.17.2024.10.03.10.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:43 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:08 +0200 Subject: [PATCH 3/7] iio: ad7192: copy/release available filter frequencies to fix race Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-3-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 While available filter frequencies are being printed to sysfs by iio core (iio_read_channel_info_avail), the sampling frequency might be changed. This could cause the buffer shared with iio core to be corrupted. To prevent it, make a copy of the filter frequencies buffer and free it in the read_avail_release_resource callback. Signed-off-by: Matteo Martelli --- drivers/iio/adc/ad7192.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index 7042ddfdfc03ee5ea58ca07fb1943feb6538175b..acf625ced0b21db8d44f77929e8a875b3c10e1b1 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -1056,12 +1056,19 @@ static int ad7192_read_avail(struct iio_dev *indio_dev, *length = ARRAY_SIZE(st->scale_avail) * 2; return IIO_AVAIL_LIST; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - *vals = (int *)st->filter_freq_avail; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: { *type = IIO_VAL_FRACTIONAL; *length = ARRAY_SIZE(st->filter_freq_avail) * 2; + guard(mutex)(&st->lock); + + *vals = kmemdup_array((int *)st->filter_freq_avail, *length, + sizeof(int), GFP_KERNEL); + if (!*vals) + return -ENOMEM; + return IIO_AVAIL_LIST; + } case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *vals = (int *)st->oversampling_ratio_avail; *type = IIO_VAL_INT; @@ -1073,6 +1080,14 @@ static int ad7192_read_avail(struct iio_dev *indio_dev, return -EINVAL; } +static void ad7192_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + if (mask == IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) + kfree(vals); +} + static int ad7192_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { struct ad7192_state *st = iio_priv(indio_dev); @@ -1098,6 +1113,7 @@ static const struct iio_info ad7192_info = { .write_raw = ad7192_write_raw, .write_raw_get_fmt = ad7192_write_raw_get_fmt, .read_avail = ad7192_read_avail, + .read_avail_release_resource = ad7192_read_avail_release_res, .attrs = &ad7192_attribute_group, .validate_trigger = ad_sd_validate_trigger, .update_scan_mode = ad7192_update_scan_mode, @@ -1108,6 +1124,7 @@ static const struct iio_info ad7194_info = { .write_raw = ad7192_write_raw, .write_raw_get_fmt = ad7192_write_raw_get_fmt, .read_avail = ad7192_read_avail, + .read_avail_release_resource = ad7192_read_avail_release_res, .validate_trigger = ad_sd_validate_trigger, }; @@ -1116,6 +1133,7 @@ static const struct iio_info ad7195_info = { .write_raw = ad7192_write_raw, .write_raw_get_fmt = ad7192_write_raw_get_fmt, .read_avail = ad7192_read_avail, + .read_avail_release_resource = ad7192_read_avail_release_res, .attrs = &ad7195_attribute_group, .validate_trigger = ad_sd_validate_trigger, .update_scan_mode = ad7192_update_scan_mode, From patchwork Thu Oct 3 17:34:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821308 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9A311A7274; Thu, 3 Oct 2024 17:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976890; cv=none; b=T7xmFgXpUXFmXYkzv+i3wLdKUjXENXNNy/L77RbnH3350b5PGgKSR6qP5qCmhV621lu2/G9V8H7qDRlZAxZf65V+F0+ui+bflKVOnf+IBhlUQl4p1TD42/FSK9aLfSS1aqAMqJCD4Zh6AHedCM5i/eQvAjs7C3YBsW2xhOq+Pxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976890; c=relaxed/simple; bh=BwkwfxY7spISjUeG5NWq77uUBqX8tksgbEX8sw7i5ew=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d9y7AoHcRQcaf61nytpVn/TwGpHACvLkyTZcT9J+9fRdAbjGNau2EXbzHIxvcFrdJUjiiL5JwhLaq9jCoZ9G0G4klXkmOrXRrLq37fSfHj4tbAs3kmkLv9qiLjg1iYniyi6WiUnITUzbnw+1CxpTgh8CFWXUt/gsYSkhhwXRFNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G3Xnzutd; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G3Xnzutd" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42cde6b5094so12346805e9.3; Thu, 03 Oct 2024 10:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976887; x=1728581687; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aIOyU8JZdm9rKnfAkxyj8k3zSsK6gIxY9/0V5bPGqQ4=; b=G3Xnzutdafx8jnFfvxpNu6Kh/iq1CabJYgSX4AgI+XQvMmw9FjixZbLEOCJtp+VzsH 6hPtM3Rmkusgk1Zpxn67DpA0HPST8si4cXzPTyB1ZQlk0GMHSFSPXBTWybZk/Vf50V2i xihaffZ3I2RHmT8HNHcqja6ta/dk1Z2/1gRbPYt6J37x+JIGqMwQbKfuDyqJbndiWNwt Bx7/VZH0zCAvUgm3AL1+lmZ67hir27rEcnXFIrLKzBLx+ys6gm4R+06YIcHCFcU/Bzdb Ua1ByjePsgX/u7Cjy9zx0eLJivRop4iA5aWG9HLCxNrlvxJXEJ5yvfrOZX84atUb/fLr K/pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976887; x=1728581687; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aIOyU8JZdm9rKnfAkxyj8k3zSsK6gIxY9/0V5bPGqQ4=; b=q85J05AS8ZMargzzFBrVTSwAx1rEbv1hNYONSjrZjlxRwDl4KoNWqx1qhnj6bApz1n pzBuC5TzzrrxQWXGK7IG2Rp5Shu+DgQrfOMk4K2/z4oNUwiFtw7DkmwtrHtAvy4SEtH+ S/85mNftRrK1f6YI2YJJ7O2zm8E354OXl98vdzZCw74HaTmBthBrOdZXOo2peTQXCEOD +GROGOBEkRIMnDFDqfak5+pGbtBzNUxH/9UwhdBkUKjrQLZW0XbhoLp772QCYZzQEzBO 7H/hygU7EcRODux6wSLUcLC0Crh7/sl+zbMFZVgEGrurbkK3nx9hK7A98XIEyU+hMIQH gZ5g== X-Forwarded-Encrypted: i=1; AJvYcCUO76Wy5kUMy/f9j7nTLn8YzQw40yAtkzAsg0gNBYDebGYCwIHGavCJRQDeEJzDtBfWyHQbstJSxOmVMQ==@vger.kernel.org, AJvYcCVG6LSmzv/00pu+iRVUA8hCYGW+V7I9XBblH/EdxAo32TB2AUlcLXgrX/zDnCX1tfUgP+i/USthwrc=@vger.kernel.org, AJvYcCVXki6X6l1yb6+BN/anHWii3XbhmCZPTVe92KtbjgQ/S6vBMHL+he+nluSkGCflUF2Onrj7DEb94/lls/g=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6QTMjWwB/yW4wTbm5TuIeQUf4RyH3I1vjEhUrWJTO9oAdpZ+P Cxf/iPp9RsY1umqemdl6561sV2gKQrWnGXyrPvtFIMaki+wu+oKR X-Google-Smtp-Source: AGHT+IGJeDpDSVTh17SxMUmozLKr9gKLlqcvFK149kyIL1NXGR4+hoZgtndY8d1QvwOqny1rM2k8DQ== X-Received: by 2002:a05:600c:138a:b0:42c:b9a5:ebbc with SMTP id 5b1f17b1804b1-42f777c7dd4mr65087785e9.16.1727976887054; Thu, 03 Oct 2024 10:34:47 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d0822b878sm1713240f8f.44.2024.10.03.10.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:46 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:09 +0200 Subject: [PATCH 4/7] iio: as73211: copy/release available integration times to fix race Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-4-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 While available integration times are being printed to sysfs by iio core (iio_read_channel_info_avail), the sampling frequency might be changed. This could cause the buffer shared with iio core to be corrupted. To prevent it, make a copy of the integration times buffer and free it in the read_avail_release_resource callback. Signed-off-by: Matteo Martelli --- drivers/iio/light/as73211.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c index be0068081ebbbb37fdfb252b67a77b302ff725f6..520c898e0ff9c530b4fdd45589559f9014d7992c 100644 --- a/drivers/iio/light/as73211.c +++ b/drivers/iio/light/as73211.c @@ -493,17 +493,33 @@ static int as73211_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec co *type = IIO_VAL_INT; return IIO_AVAIL_LIST; - case IIO_CHAN_INFO_INT_TIME: + case IIO_CHAN_INFO_INT_TIME: { *length = ARRAY_SIZE(data->int_time_avail); - *vals = data->int_time_avail; *type = IIO_VAL_INT_PLUS_MICRO; - return IIO_AVAIL_LIST; + guard(mutex)(&data->mutex); + + *vals = kmemdup_array(data->int_time_avail, *length, + sizeof(int), GFP_KERNEL); + if (!*vals) + return -ENOMEM; + + return IIO_AVAIL_LIST; + } default: return -EINVAL; } } +static void as73211_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + if (mask == IIO_CHAN_INFO_INT_TIME) + kfree(vals); +} + + static int _as73211_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan __always_unused, int val, int val2, long mask) @@ -699,6 +715,7 @@ static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p) static const struct iio_info as73211_info = { .read_raw = as73211_read_raw, .read_avail = as73211_read_avail, + .read_avail_release_resource = as73211_read_avail_release_res, .write_raw = as73211_write_raw, }; From patchwork Thu Oct 3 17:34:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821309 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6752E1ABEA1; Thu, 3 Oct 2024 17:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976892; cv=none; b=GkOck/g2/klAJzmrpt+ofJZ8TUYaVe//elGnFKt9d3MXvmEFBWq1T92epGOuKFl+z083or5+RqCMOmx9oRAHRTZMnU0oUs1KWHWO1ma8ys3NgFH8fNVWqzkpAaMDgXbobVCm2iY0q7zd5hrSnMHbVptsPQmEfqzYb0Se8va6H88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976892; c=relaxed/simple; bh=JI696ir0QITrxWEfRcF3ZHdp8+XMqxpwlGo9q4ElXuU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gjgYTHJ4XB2DJgNuVHF879Z5J/WN9VxGYfjPDW0rmynRm6xwFKwsnw7X1Y6xN/4OmYWCfJ/i/l6ixft48uv7viU67N4SWrMcCI9GGRH0Ryf4zQNuoK2qCm03W7CPW5Av/aCSrV+Z3Lmd8MfY+f7VMu+A5zubDuY0CPb+CJiBF0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MpmGUrx0; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MpmGUrx0" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cb806623eso10208715e9.2; Thu, 03 Oct 2024 10:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976889; x=1728581689; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lQLemq3ZBEgFeRrStV/dpS5btl0G+M2whUJOsHCfVSQ=; b=MpmGUrx0m//kfyQbrdm9l+dary9yMIzKIq629v47umAV+4EI9i0Z5+uGKx58yv9s05 yIni+55i5gambxiam/BEeReWew0SdeTQ6ydZQHS8/TaZLcT34vEnj+ZAel2osSqHXMi1 Vwm2y+MzzxqvCNuPwxL3jC32Q2Tqax0Jl526croxnygUZssb1tMMWYrg/z6QSmvMAzEw 45TSDhyem7+G2pSYY4qaxQIIJOBf4Zci56kZB1CCRiGOswuk3HO3pcI07EdRIUz7k5yd qpitKXJkNFylXIbXGAFHUael/nsl3EBbCulmx7d2uqRBbCIi5DZSNlifuhQO+S8hsmHC qnLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976889; x=1728581689; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lQLemq3ZBEgFeRrStV/dpS5btl0G+M2whUJOsHCfVSQ=; b=H8RSdpewlkRshwNluWImK5OiSf0FF8ZzKc/Jtl3f8Oq8lkzfJNsp96srWiXT079h3E YsWAhQW+DjyrPDEKxyoOjmByTPta5WDE9FfacNSyP+chSwoPfauyWIea60fg7yEMw3HL kVkF1giAfLAgRwntzYfxQ6oJ4czEiiYNVRVrbsb8mqt4JtR66lqR2QavrJsGtigqmxiH mqhyyyxQDxRVmACSrSi2z1r4URIzYyv9BOmpEypjHTS0RlnM8NXKvcUTgJeVbHW/GYzh X8NRNmBYfr6Eiz3zmdjwmY6s4wvox62e0Uqd4Mj0NFLD2n6NI/cew3tPLnOOM/Epd3++ Zh7A== X-Forwarded-Encrypted: i=1; AJvYcCVsinTDeIHvtuKDe2iHagBtOV43IiF559xWbviSsMqzzp/YNjwFz2FWAl1EN8OXOBpskbVs4+SOp4G7744=@vger.kernel.org, AJvYcCW946HTkbmD2EGxakMnqEsKVPkkRxOCXptnNE789fp+Y4o40FvAfh/zcHoDqoBA6D5hhp8NENyAQMs=@vger.kernel.org, AJvYcCWTlhGfijAx8/gfvIL5BPOkwZ0M4cCcSuTzRS7HCztFXjaY9gYwJB/GM+FermvLzdU8oiq20xZqnUvhLw==@vger.kernel.org X-Gm-Message-State: AOJu0Yy8jMmVAk/n4tB5uFpTm2w1F/Vg8gAP4KuPIrkRLFFEj3076uId 2T3vNzMH+YbKumSX/InXVy98vIXTs3LVse75OD+MkO0PbGxx12Xr X-Google-Smtp-Source: AGHT+IGAma1RySn1IK/rp0LtN48vO0lX02UU0J0RCmsTD86qOQ0N6ZY4suhHS5IMu/uczXymL5Wx4g== X-Received: by 2002:a5d:6506:0:b0:371:8c61:577c with SMTP id ffacd0b85a97d-37d0e7373dfmr115647f8f.26.1727976888631; Thu, 03 Oct 2024 10:34:48 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d082e6de8sm1713425f8f.114.2024.10.03.10.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:47 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:10 +0200 Subject: [PATCH 5/7] iio: inkern: copy/release available info from producer Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-5-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 Consumers need to call the read_avail_release_resource after reading the available info. To call the release with info_exists locked, copy the available info from the producer and immediately call its release callback. With this change, users of iio_read_avail_channel_raw() and iio_read_avail_channel_attribute() must free the copied avail info after calling them. Signed-off-by: Matteo Martelli --- drivers/iio/inkern.c | 64 +++++++++++++++++++++++++++++++++----------- include/linux/iio/consumer.h | 4 +-- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 7f325b3ed08fae6674245312cf8f57bb151006c0..cc65ef79451e5aa2cea447e168007a447ffc0d91 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -760,9 +760,25 @@ static int iio_channel_read_avail(struct iio_channel *chan, if (!iio_channel_has_available(chan->channel, info)) return -EINVAL; - if (iio_info->read_avail) - return iio_info->read_avail(chan->indio_dev, chan->channel, - vals, type, length, info); + if (iio_info->read_avail) { + const int *vals_tmp; + int ret; + + ret = iio_info->read_avail(chan->indio_dev, chan->channel, + &vals_tmp, type, length, info); + if (ret < 0) + return ret; + + *vals = kmemdup_array(vals_tmp, *length, sizeof(int), GFP_KERNEL); + if (!*vals) + return -ENOMEM; + + if (iio_info->read_avail_release_resource) + iio_info->read_avail_release_resource( + chan->indio_dev, chan->channel, vals_tmp, info); + + return ret; + } return -EINVAL; } @@ -789,9 +805,11 @@ int iio_read_avail_channel_raw(struct iio_channel *chan, ret = iio_read_avail_channel_attribute(chan, vals, &type, length, IIO_CHAN_INFO_RAW); - if (ret >= 0 && type != IIO_VAL_INT) + if (ret >= 0 && type != IIO_VAL_INT) { /* raw values are assumed to be IIO_VAL_INT */ + kfree(*vals); ret = -EINVAL; + } return ret; } @@ -820,24 +838,31 @@ static int iio_channel_read_max(struct iio_channel *chan, if (val2) *val2 = vals[5]; } - return 0; + ret = 0; + break; case IIO_AVAIL_LIST: - if (length <= 0) - return -EINVAL; + if (length <= 0) { + ret = -EINVAL; + goto out; + } switch (*type) { case IIO_VAL_INT: *val = max_array(vals, length); + ret = 0; break; default: /* TODO: learn about max for other iio values */ - return -EINVAL; + ret = -EINVAL; } - return 0; + break; default: - return -EINVAL; + ret = -EINVAL; } +out: + kfree(vals); + return ret; } int iio_read_max_channel_raw(struct iio_channel *chan, int *val) @@ -876,24 +901,31 @@ static int iio_channel_read_min(struct iio_channel *chan, if (val2) *val2 = vals[1]; } - return 0; + ret = 0; + break; case IIO_AVAIL_LIST: - if (length <= 0) - return -EINVAL; + if (length <= 0) { + ret = -EINVAL; + goto out; + } switch (*type) { case IIO_VAL_INT: *val = min_array(vals, length); + ret = 0; break; default: /* TODO: learn about min for other iio values */ - return -EINVAL; + ret = -EINVAL; } - return 0; + break; default: - return -EINVAL; + ret = -EINVAL; } +out: + kfree(vals); + return ret; } int iio_read_min_channel_raw(struct iio_channel *chan, int *val) diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 333d1d8ccb37f387fe531577ac5e0bfc7f752cec..e3e268d2574b3e01c9412449d90d627de7efcd84 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h @@ -316,7 +316,7 @@ int iio_read_min_channel_raw(struct iio_channel *chan, int *val); /** * iio_read_avail_channel_raw() - read available raw values from a given channel * @chan: The channel being queried. - * @vals: Available values read back. + * @vals: Available values read back. Must be freed after use. * @length: Number of entries in vals. * * Returns an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST. @@ -334,7 +334,7 @@ int iio_read_avail_channel_raw(struct iio_channel *chan, /** * iio_read_avail_channel_attribute() - read available channel attribute values * @chan: The channel being queried. - * @vals: Available values read back. + * @vals: Available values read back. Must be freed after use. * @type: Type of values read back. * @length: Number of entries in vals. * @attribute: info attribute to be read back. From patchwork Thu Oct 3 17:34:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821310 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8074B1AC885; Thu, 3 Oct 2024 17:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976895; cv=none; b=n2g81vSD5LN2xm2xruLayos76kr37PzwE5DmCj3gdgfDEj6IiSuw264utYitIhTWHnYkYvhaAP7Uf0XPGoaydOI8od8Ev0Xv3dKXWcrqWFOcbXBvjVRyLghHQ0AUJ4Pzny1/Z9QM0U6GUvl7Jdclmam9mzkkrg+3gUFX/p5MsfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976895; c=relaxed/simple; bh=58F1FuUmxNDA0vLWh1R6mPGi8+44AWjAUzE2ru9NTEc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mC6cCWV9tivAJB3uxPxPkWNws8HEEEPk2B7o5Uxcc2NZ5+YfEyfd8P9Dmuv+sYaWclRHcVy170/cLyJCNnzhrCG+S8+rkVG2pVFmi0ryeldytjEL/Wj9KAkGL+JI3HBIvKUKpg8D/BQQXqQmkAI5+hrOJ1KQ//1DJTwz4fmY7tM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GTCh9CmM; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GTCh9CmM" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42cde6b5094so12347535e9.3; Thu, 03 Oct 2024 10:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976892; x=1728581692; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=h0wZJpbdLI8pbhpRpC30fTnveQVaUWJzRu/TLRmsvgA=; b=GTCh9CmMrZJHGKTEeL2z5Kou2VUBidRX/UaICe7U0E22hgCDEYqTAbUHWdA9DeSb/E XMujMAHdQWnAeNdcBgTsmTOL9/ntUzF6ilNEliOky6VidXAwFi9stHmDJBmsJGpvzCYP WKBXO8IRMNy0YXtk7kt/AvAkWc43shNeO6Z+IMEzPJIniD9tC/2IuU77Oe1KHIwRTB/T lhvWQk4ejYiRhED3eM1HOJDdPLFmFB6BRpJxfi6a3yr0WDDP9B9/IyZtBLhqbuPIW3rq iab5fs7gbCAdPHs75TvjnOlxAErfrebShVGBJgEHwbCZv3KGd7bkyNuymdEqaqK/VDhD 0FVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976892; x=1728581692; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h0wZJpbdLI8pbhpRpC30fTnveQVaUWJzRu/TLRmsvgA=; b=ansAIGjDWhR8cPM7jW0HQXGidHgClorwIlrU5TS61eOjT0ZN/AoOQ1Eswv3VemawuY DTmmRFYN8qvEDmpdu4pQpT9xuTx2AXxnRh6CFStQks750dh01FWA/nCZX3OL/E4vVTuU eunwAzdYbd1ye//xovZpDighYUhhcT5mBZc4a06M1+cf3ttxW9TtlLQN6qp9R7gR96NT GKUTGoQb8ABEcr64KAQHGr0nUjrxb4Pou5CjmyVm4WyFM1ay6pV6C3eRTJJGgT4hMBkM cxTv5WWqn/POygKAHR9HNN7ddxSCPUxrRLRTn7pNPPVx7AuRrZUusjR8Xg5nSuo695GC 2m1A== X-Forwarded-Encrypted: i=1; AJvYcCUgrgK3NuB2KTymO4qWa4FeFj04pIsR/v98mex1mgqFDRpO8NAMvi3CoUufRSqf7N4sgyM4Or2upGMesdE=@vger.kernel.org, AJvYcCUxAD/dk1rWOI4zkH0QziSKqBSvQCNexWM09ybdMzAnqAxSiWA/jPo1cknpt2GInsmc4tlCbjlTGIiRFA==@vger.kernel.org, AJvYcCXWBnS2EjzkGgpDG68LPg+3/0gVHc3ZuPpzu6ND3ooznjbP6JRFye7VKwK1wltVyosMGf08+eEwlNY=@vger.kernel.org X-Gm-Message-State: AOJu0YzIQMhh5y+FVOkLXPN8JcHB7VLBihfuGXyBgNlSjFJNDxcA9+KF YfZyhIh9OMHPPfeiwOf1lAKB6kK9wUhgC0FdZzjBTDXvwBdpCA1/ X-Google-Smtp-Source: AGHT+IEAM0vwSFq50GSJ3eNFzY5HI4Y9topN38B5pNnWozwRsePt2tQX9c839MYYWXekBQnwEFA3sg== X-Received: by 2002:adf:ff8d:0:b0:37c:cf72:f248 with SMTP id ffacd0b85a97d-37d0e8f553bmr84990f8f.50.1727976891737; Thu, 03 Oct 2024 10:34:51 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f802643e2sm20606315e9.21.2024.10.03.10.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:50 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:11 +0200 Subject: [PATCH 6/7] iio: consumers: release available info buffer copied from producer Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-6-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 The iio_read_avail_channel_raw() inkern interface now allocates a copy of the available info buffer that must be freed after use. To do so, free the buffer in the consumers read_avail_relese_resource callback. Signed-off-by: Matteo Martelli --- drivers/iio/afe/iio-rescale.c | 8 ++++++++ drivers/iio/dac/dpot-dac.c | 8 ++++++++ drivers/iio/multiplexer/iio-mux.c | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 56e5913ab82d1c045c9ca27012008a4495502cbf..78bb86c291706748b4072a484532ad20c415ff9f 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -249,9 +249,17 @@ static int rescale_read_avail(struct iio_dev *indio_dev, } } +static void rescale_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + kfree(vals); +} + static const struct iio_info rescale_info = { .read_raw = rescale_read_raw, .read_avail = rescale_read_avail, + .read_avail_release_resource = rescale_read_avail_release_res, }; static ssize_t rescale_read_ext_info(struct iio_dev *indio_dev, diff --git a/drivers/iio/dac/dpot-dac.c b/drivers/iio/dac/dpot-dac.c index 7332064d0852d979620f90066fb027f6f68f8c95..beec76247acb5170b81058d28a71ed17c831c905 100644 --- a/drivers/iio/dac/dpot-dac.c +++ b/drivers/iio/dac/dpot-dac.c @@ -108,6 +108,13 @@ static int dpot_dac_read_avail(struct iio_dev *indio_dev, return -EINVAL; } +static void dpot_dac_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + kfree(vals); +} + static int dpot_dac_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -125,6 +132,7 @@ static int dpot_dac_write_raw(struct iio_dev *indio_dev, static const struct iio_info dpot_dac_info = { .read_raw = dpot_dac_read_raw, .read_avail = dpot_dac_read_avail, + .read_avail_release_resource = dpot_dac_read_avail_release_res, .write_raw = dpot_dac_write_raw, }; diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c index 2953403bef53bbe47a97a8ab1c475ed88d7f86d2..31345437784b01c5d6f8ea70263f4c2574388e7a 100644 --- a/drivers/iio/multiplexer/iio-mux.c +++ b/drivers/iio/multiplexer/iio-mux.c @@ -142,6 +142,13 @@ static int mux_read_avail(struct iio_dev *indio_dev, return ret; } +static void mux_read_avail_release_res(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int *vals, long mask) +{ + kfree(vals); +} + static int mux_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -171,6 +178,7 @@ static int mux_write_raw(struct iio_dev *indio_dev, static const struct iio_info mux_info = { .read_raw = mux_read_raw, .read_avail = mux_read_avail, + .read_avail_release_resource = mux_read_avail_release_res, .write_raw = mux_write_raw, }; From patchwork Thu Oct 3 17:34:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Martelli X-Patchwork-Id: 13821311 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 758871AD3E1; Thu, 3 Oct 2024 17:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976897; cv=none; b=u31Y4HvysKfzbCDbAnfBVuDV8pcQ6C5aDQ0vhYckMl32JyovGxtinaV5kb1nyIA4sZcQeOZuNEtSOsNe0vOdP3QesPNsnib4TPzKEdBUHb5OoOcNBjCr5gzIMu3Z3hJDTuYx58/kabJHiw9WpyWsegqHIwahynXPT/JqvYVT1AQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727976897; c=relaxed/simple; bh=3D2UcZCozg5mtziUUk5vTYahXBxocqjYckSdyK5dx/8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qTsV0VFzJmDNRJzxyrQhq0E9AIJnrE3pSDLW5FXfBXcsXqcpHMDVw2gTCt+ngxbt1bA85D3nNkivi8nX0r2pm566OogG5ZucO88KKaQ6Bda2PB0O9h/sygOZHzbWFSmjzkZWW9tJd0qkwPYWOgVDXmSa8boUU0674fcUtfqgWSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hx2d8os3; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hx2d8os3" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-42cb60aff1eso11867655e9.0; Thu, 03 Oct 2024 10:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727976894; x=1728581694; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Wz8mn2zxSXqsVq5jkg3nHNCDHyd967M2Mt/0lSJOZUc=; b=hx2d8os36c9WcoaPIIQpCCfFRu9j2513p4LAPlx+tjy/RPnlSjZxF28RLShzVsDDvt FLFdNFFAVLqnpE1ze2ykP6Qgkz0VogVCYy+JZ7QjKWHsHo47cCOqO837VrUcjXRCRPOT /IWcxZJT6RKY+aCQcAfrik1r1BeHYf4EjlOVRVttlcHK5dsabRNpdAC86i4FBeFMVeVt 3dXUCMIxrAGSsdIzKF2f+Ys9et4I0oUgZfB5SdzfZCu9i8+wnqdfgQDzhGZbeMQGat5q +z8Qo/BRbbZF7/ir0VnKz01tBz1RNOoH5cB4JO4+cWjRYv/O801Hqy8uLo0mrxtPrBOI ejXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727976894; x=1728581694; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wz8mn2zxSXqsVq5jkg3nHNCDHyd967M2Mt/0lSJOZUc=; b=JwK4pet0odxR0Ytu6n7IcMzFJDdIpfsUNcBT5AJ2l0zQlUBMEBw4DWlzSXAacp/1DP HsnfnDx4PajJlAHw2EDi8+NARsnvugdOPzoCgd/uGGbpD4J/T51r9URA91OgWZ9XLSwC z9pZfDZq4xP80nhug/udJMqkP3qa1a9yiIHSIniVeMrLMTbqgvJGt3AZ9mloYCSguwXQ IBK/EiVa/KQNwzW9LPeTZdsvX4BabSpveA/VrRDlDK4yYXpEz5jAGVTCSnfg/kcWwtcb 8RZrCsVeSPH5QHftfBNMoc5dpez+8hCRZKQ/+H/DKgkh4IFGPETypLeLmkEkhqbkYjkH Ky8w== X-Forwarded-Encrypted: i=1; AJvYcCUKyyiQfRnjyZ7VVpGUvdlzl1JTO6QtaOrx0v0ClgpJHY7cZdqlWe8kuPfdmr7t43XFyV3qsOyShIKnXwY=@vger.kernel.org, AJvYcCWa98UxnJfNcdhnM0FaaHWtgUErgD9EcqOMak2pFU1cPmTOhntisYLhPdnjFGNvh600CfP7btpoLF/cDg==@vger.kernel.org, AJvYcCXVR8RV6ciOxAYdeP7BUMl0MTiuOgeq3sfZmdx6quh7kPWb1rLUgW6kBt8PS3xYgZ30fH9AayC6YCY=@vger.kernel.org X-Gm-Message-State: AOJu0YzOWVcwvLoMnEzcufdSYOaZB6U1kScQYlx5BD/t1d3ZoWyg2TPM nAP6zuDQZfdnvC2vKtg2zMFV8HNNCQmQH4J9bMjjH3xXBZn8HbLl X-Google-Smtp-Source: AGHT+IHo+APz86h00PjtGq6DOnGX3/XEFKhnzXvT9fk7SgBeKfuGQG+33H6UlRik9DhMNcXPUe6fzA== X-Received: by 2002:a05:600c:1d25:b0:42b:8a35:1acf with SMTP id 5b1f17b1804b1-42f778f2bb8mr66032595e9.25.1727976893476; Thu, 03 Oct 2024 10:34:53 -0700 (PDT) Received: from localhost (host-79-19-52-27.retail.telecomitalia.it. [79.19.52.27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f79eadd8csm49640315e9.16.2024.10.03.10.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 10:34:52 -0700 (PDT) From: Matteo Martelli Date: Thu, 03 Oct 2024 19:34:12 +0200 Subject: [PATCH 7/7] power: supply: ingenic-battery: free scale buffer after use Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241003-iio-read-avail-release-v1-7-c70cc7d9c2e0@gmail.com> References: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> In-Reply-To: <20241003-iio-read-avail-release-v1-0-c70cc7d9c2e0@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Alisa-Dariana Roman , Christian Eggers , Peter Rosin , Paul Cercueil , Sebastian Reichel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-pm@vger.kernel.org, Matteo Martelli X-Mailer: b4 0.14.2 The iio_read_avail_channel_attribute() iio interface now allocates a copy of the available info buffer that must be freed after use. Signed-off-by: Matteo Martelli --- drivers/power/supply/ingenic-battery.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c index 0a40f425c27723ccec49985b8b5e14a737b6a7eb..fa6d6898f8722cc8e06a888a762a3edeb0474a6e 100644 --- a/drivers/power/supply/ingenic-battery.c +++ b/drivers/power/supply/ingenic-battery.c @@ -79,8 +79,10 @@ static int ingenic_battery_set_scale(struct ingenic_battery *bat) dev_err(bat->dev, "Unable to read channel avail scale\n"); return ret; } - if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2) - return -EINVAL; + if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2) { + ret = -EINVAL; + goto out; + } max_mV = bat->info->voltage_max_design_uv / 1000; @@ -99,7 +101,8 @@ static int ingenic_battery_set_scale(struct ingenic_battery *bat) if (best_idx < 0) { dev_err(bat->dev, "Unable to find matching voltage scale\n"); - return -EINVAL; + ret = -EINVAL; + goto out; } /* Only set scale if there is more than one (fractional) entry */ @@ -109,10 +112,13 @@ static int ingenic_battery_set_scale(struct ingenic_battery *bat) scale_raw[best_idx + 1], IIO_CHAN_INFO_SCALE); if (ret) - return ret; + goto out; } - return 0; + ret = 0; +out: + kfree(scale_raw); + return ret; } static enum power_supply_property ingenic_battery_properties[] = {