From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50DD68F5E for ; Mon, 3 Oct 2022 08:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664786610; x=1696322610; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=POqTCHFhgHZP4PJehVBeukvn0cF46F+fSY63iPQxsWs=; b=Q2pTYVbwZ7Y5RlJPvO+0AiO38wMsuWXG6Q378FpXHXlA8OEcDTbw2hNw Cm7oatQjI46iRjy5mBr8fKSDFddi/EfF2hmI2qWvjzFHfrVJbD5D2HLLP ZLe8mFlh+kVXfUXLAX9uOhdezU/CmkS9GjSfMMXtDwmSomqumcWrANm03 g9O3rOgsMSYO6/Kfep9iU9zgqAYlP2+l88nMcAlTtmUkCIjJ85g7AF+vt xZqjj28JBKql0sc6goxkxomJUqLXETCwIqrXzAX23LWg5xtKsirYol59V pe/RcdnnsUwQdmovgouUogehElj6bBlUH9W/mVBpcXWscBCOi9kmolcmf g==; X-IronPort-AV: E=McAfee;i="6500,9779,10488"; a="300183812" X-IronPort-AV: E=Sophos;i="5.93,365,1654585200"; d="scan'208";a="300183812" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 01:43:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10488"; a="748908010" X-IronPort-AV: E=Sophos;i="5.93,365,1654585200"; d="scan'208";a="748908010" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga004.jf.intel.com with ESMTP; 03 Oct 2022 01:43:23 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1ofH2n-001Pzs-09; Mon, 03 Oct 2022 11:43:21 +0300 Date: Mon, 3 Oct 2022 11:43:20 +0300 From: Andy Shevchenko To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , Michael Hennerich , Cosmin Tanislav , Jonathan Cameron , Eugen Hristev , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Benson Leung , Guenter Roeck , Alexandru Ardelean , Nathan Chancellor , Miquel Raynal , Miaoqian Lin , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Paul Cercueil , Mihail Chindris , Gwendal Grignou , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chrome-platform@lists.linux.dev Subject: Re: [RFT PATCH v3 10/10] iio: Don't silently expect attribute types Message-ID: References: <63f54787a684eb1232f1c5d275a09c786987fe4a.1664782676.git.mazziesaccount@gmail.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <63f54787a684eb1232f1c5d275a09c786987fe4a.1664782676.git.mazziesaccount@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Mon, Oct 03, 2022 at 11:13:53AM +0300, Matti Vaittinen wrote: > The iio_triggered_buffer_setup_ext() and the > devm_iio_kfifo_buffer_setup_ext() were changed by > commit 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr") > to silently expect that all attributes given in buffer_attrs array are > device-attributes. This expectation was not forced by the API - and some > drivers did register attributes created by IIO_CONST_ATTR(). > > When using IIO_CONST_ATTRs the added attribute "wrapping" does not copy > the pointer to stored string constant and when the sysfs file is read the > kernel will access to invalid location. > > Change the function signatures to expect an array of iio_dev_attrs to > avoid similar errors in the future. ... Wouldn't be better to split this on per driver basis or is it impossible? > drivers/iio/accel/adxl367.c | 10 +++++----- > drivers/iio/accel/adxl372.c | 10 +++++----- > drivers/iio/accel/bmc150-accel-core.c | 12 ++++++------ > drivers/iio/adc/at91-sama5d2_adc.c | 12 ++++++------ > drivers/iio/buffer/industrialio-buffer-dmaengine.c | 4 ++-- > drivers/iio/buffer/industrialio-triggered-buffer.c | 4 ++-- > drivers/iio/buffer/kfifo_buf.c | 2 +- > .../common/cros_ec_sensors/cros_ec_sensors_core.c | 6 +++--- > drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 8 ++++---- > drivers/iio/industrialio-buffer.c | 11 +++++++---- > include/linux/iio/buffer_impl.h | 2 +- > include/linux/iio/kfifo_buf.h | 3 ++- > include/linux/iio/triggered_buffer.h | 6 +++--- ... > struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); > struct iio_dev_attr *p; > + const struct iio_dev_attr *id_attr; I'm wondering if we may keep this upper, so "longer line goes first" rule would be satisfied. > struct attribute **attr; > int ret, i, attrn, scan_el_attrcount, buffer_attrcount; > const struct iio_chan_spec *channels; ... > + for (i = 0, id_attr = buffer->attrs[i]; > + (id_attr = buffer->attrs[i]); i++) Not sure why we have additional parentheses... > + attr[ARRAY_SIZE(iio_buffer_attrs) + i] = > + (struct attribute *)&id_attr->dev_attr.attr; ...and explicit casting here. Isn't attr is already of a struct attribute? -- With Best Regards, Andy Shevchenko