linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@linux.dev>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "O'Griofa, Conall" <conall.ogriofa@amd.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels in scan_mask
Date: Mon, 18 Mar 2024 11:18:43 -0400	[thread overview]
Message-ID: <7ee83f15-88fc-4530-84b7-b8ee31663dbc@linux.dev> (raw)
In-Reply-To: <20240316133627.5d2bf585@jic23-huawei>

On 3/16/24 09:36, Jonathan Cameron wrote:
> On Fri, 15 Mar 2024 13:47:40 -0400
> Sean Anderson <sean.anderson@linux.dev> wrote:
> 
>> Hi Conall,
>> 
>> On 3/15/24 09:18, O'Griofa, Conall wrote:
>> > [AMD Official Use Only - General]
>> > 
>> > Hi,
>> > 
>> > I think there was a fix for this issue applied to the version that was running on 5.15 that didn't seem to make it into the upstream driver.
>> > Please see link for reference https://github.com/Xilinx/linux-xlnx/commit/608426961f16ab149b1b699f1c35f7ad244c0720
>> > 
>> > I think a similar fix to the above patch is may be beneficial?  
>> 
>> These patches look functionally identical to me.
> 
> Because there are no channels with scan index between
> 22 * 2 + 16 (that patch) and 22 * 3 (your patch) that is
> the effect is indeed the same. But given the issues is the
> 64 limit on maximum scan index, 22 * 3 = 66 is an ugly value
> to compare with.
> 
> I'm still very against the use of scan_index for anything other
> than scan indices (which is why partly how this bug wasn't noticed
> in the first palce). So the check should be scan_index != -1
> and uses of those values elsewhere in the driver should be fixed
> (which looks simple to do from a quick glance at the code).

OK, so how do the sysfs files get named then?

--Sean

>> 
>> --Sean
>> 
>> >> -----Original Message-----
>> >> From: Sean Anderson <sean.anderson@linux.dev>
>> >> Sent: Thursday, March 14, 2024 5:30 PM
>> >> To: Jonathan Cameron <jic23@kernel.org>
>> >> Cc: linux-iio@vger.kernel.org; O'Griofa, Conall <conall.ogriofa@amd.com>;
>> >> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Lars-Peter
>> >> Clausen <lars@metafoo.de>
>> >> Subject: Re: [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels in
>> >> scan_mask
>> >>
>> >> Caution: This message originated from an External Source. Use proper caution
>> >> when opening attachments, clicking links, or responding.
>> >>
>> >>
>> >> On 3/14/24 11:48, Jonathan Cameron wrote:  
>> >> > On Mon, 11 Mar 2024 12:28:00 -0400
>> >> > Sean Anderson <sean.anderson@linux.dev> wrote:
>> >> >  
>> >> >> ams_enable_channel_sequence constructs a "scan_mask" for all the PS
>> >> >> and PL channels. This works out fine, since scan_index for these
>> >> >> channels is less than 64. However, it also includes the
>> >> >> ams_ctrl_channels, where scan_index is greater than 64, triggering
>> >> >> undefined behavior. Since we don't need these channels anyway, just  
>> >> exclude them.  
>> >> >>
>> >> >> Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver")
>> >> >> Signed-off-by: Sean Anderson <sean.anderson@linux.dev>  
>> >> >
>> >> > Hi Sean,
>> >> >
>> >> > I'd ideally like to understand why we have channels with such large
>> >> > scan indexes.  Those values should only be used for buffered capture.
>> >> > It feels like they are being abused here.  Can we set them to -1
>> >> > instead and check based on that?
>> >> > For a channel, a scan index of -1 means it can't be captured via the
>> >> > buffered interfaces but only accessed via sysfs reads.
>> >> > I think that's what we have here?  
>> >>
>> >> From what I can tell, none of the channels support buffered reads. And we can't
>> >> naïvely convert the scan_index to -1, since that causes sysfs naming conflicts
>> >> (not to mention the compatibility break).
>> >>  
>> >> >
>> >> > I just feel like if we leave these as things stand, we will get bitten
>> >> > by similar bugs in the future.  At least with -1 it should be obvious why!  
>> >>
>> >> There are just as likely to be bugs confusing the PL/PS subdevices...
>> >>
>> >> FWIW I had no trouble identifying the channels involved with this bug.
>> >>
>> >> --Sean
>> >>  
>> >> > Jonathan
>> >> >
>> >> >  
>> >> >> ---
>> >> >>
>> >> >>  drivers/iio/adc/xilinx-ams.c | 8 ++++++--
>> >> >>  1 file changed, 6 insertions(+), 2 deletions(-)
>> >> >>
>> >> >> diff --git a/drivers/iio/adc/xilinx-ams.c
>> >> >> b/drivers/iio/adc/xilinx-ams.c index a55396c1f8b2..4de7ce598e4d
>> >> >> 100644
>> >> >> --- a/drivers/iio/adc/xilinx-ams.c
>> >> >> +++ b/drivers/iio/adc/xilinx-ams.c
>> >> >> @@ -414,8 +414,12 @@ static void ams_enable_channel_sequence(struct
>> >> >> iio_dev *indio_dev)
>> >> >>
>> >> >>      /* Run calibration of PS & PL as part of the sequence */
>> >> >>      scan_mask = BIT(0) | BIT(AMS_PS_SEQ_MAX);
>> >> >> -    for (i = 0; i < indio_dev->num_channels; i++)
>> >> >> -            scan_mask |= BIT_ULL(indio_dev->channels[i].scan_index);
>> >> >> +    for (i = 0; i < indio_dev->num_channels; i++) {
>> >> >> +            const struct iio_chan_spec *chan =
>> >> >> + &indio_dev->channels[i];
>> >> >> +
>> >> >> +            if (chan->scan_index < AMS_CTRL_SEQ_BASE)
>> >> >> +                    scan_mask |= BIT_ULL(chan->scan_index);
>> >> >> +    }
>> >> >>
>> >> >>      if (ams->ps_base) {
>> >> >>              /* put sysmon in a soft reset to change the sequence */  
>> >> >  
>> 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-03-18 15:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 16:28 [PATCH] iio: xilinx-ams: Don't include ams_ctrl_channels in scan_mask Sean Anderson
2024-03-14 15:48 ` Jonathan Cameron
2024-03-14 17:30   ` Sean Anderson
2024-03-15 13:18     ` O'Griofa, Conall
2024-03-15 17:47       ` Sean Anderson
2024-03-16 13:36         ` Jonathan Cameron
2024-03-18 15:18           ` Sean Anderson [this message]
2024-03-18 15:24             ` Jonathan Cameron
2024-03-18 15:28               ` Sean Anderson
2024-03-19 13:42                 ` Jonathan Cameron
2024-06-07 17:42                   ` Sean Anderson
2024-06-08 14:03                     ` Jonathan Cameron
2024-03-19 12:00         ` O'Griofa, Conall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ee83f15-88fc-4530-84b7-b8ee31663dbc@linux.dev \
    --to=sean.anderson@linux.dev \
    --cc=conall.ogriofa@amd.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).