From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2025BC4332F for ; Mon, 3 Oct 2022 09:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbiJCJoi (ORCPT ); Mon, 3 Oct 2022 05:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbiJCJoL (ORCPT ); Mon, 3 Oct 2022 05:44:11 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684F2F57; Mon, 3 Oct 2022 02:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664789987; x=1696325987; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=sXZaQocFXY9yjGwvBQtBsjXvYzr4OXfPV0g7Jm5zPAQ=; b=QnUwUvQwdhJwbNtfcUNKu7sI38OLk/HXIOhCpWgxUuCio2grX6KdcI5F Dx17ZFfD+jkLuMnMf5D1dcQy2cz/ctB4TJShHSjo5szLb+09aASSpnZIw 9+OkD8v8JVyXkpj7ZDo+x+RDxnK6ajSxMyzLtsH8ClPxeqWHCARgj9ub9 4ardnsR2dnD0Cv5j+pRKBIPTLNfhRosJHSE2N0S/46Fmm+8tZqaUIPDFe dmgyohKmPd04UFV3tys8e0AL1B3kv+GOn0BhW+HXuw+Vuqd01gGOdzb3s ueGw4sk8VSiyThU7rp0NCmCWKKLW7QSg6P7omsqmTNYODGcfnAfD6UcdI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10488"; a="289754335" X-IronPort-AV: E=Sophos;i="5.93,365,1654585200"; d="scan'208";a="289754335" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 02:39:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10488"; a="727691643" X-IronPort-AV: E=Sophos;i="5.93,365,1654585200"; d="scan'208";a="727691643" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga002.fm.intel.com with ESMTP; 03 Oct 2022 02:39:32 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1ofHv8-001Rh9-19; Mon, 03 Oct 2022 12:39:30 +0300 Date: Mon, 3 Oct 2022 12:39:30 +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> <7ae09809-4f3c-9872-5a87-0a05e73d39b4@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7ae09809-4f3c-9872-5a87-0a05e73d39b4@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Mon, Oct 03, 2022 at 12:02:56PM +0300, Matti Vaittinen wrote: > On 10/3/22 11:58, Matti Vaittinen wrote: > > On 10/3/22 11:43, Andy Shevchenko wrote: > > > On Mon, Oct 03, 2022 at 11:13:53AM +0300, Matti Vaittinen wrote: ... > > > > +            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? > > > > I am glad you asked :) > > This is one of the "things" I was not really happy about. Here we hide > > the fact that our array is full of pointers to _const_ data. If we don't > > cast the compiler points this out. Old code did the same thing but it > > did this by just doing a memcpy for the pointers - which I personally > > consider even worse as it gets really easy to miss this. The cast at > > least hints there is something slightly "fishy" going on. > > > > My "gut feeling" about the correct fix is we should check if some > > attributes in the array (stored to the struct here) actually need to be > > modified later (which I doubt). If I was keen on betting I'd bet we > > could switch the struct definition to also contain pointers to const > > attributes. I am afraid this would mean quite a few more changes to the > > function signatures (changing struct attribute * to const struct > > attribute *) here and there - and possibly also require some changes to > > drivers. Thus I didn't even look at that option in the scope of this > > fix. It should probably be a separate refactoring series. But yes - this > > cast should catch attention as it did. > > > > Actually, now that you pointed it out - do you think this would warrant a > FIXME comment? Makes sense to me, but I'm not a maintainer of IIO :-) -- With Best Regards, Andy Shevchenko