All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Mark Brown" <broonie@kernel.org>,
	"ALSA Development Mailing List" <alsa-devel@alsa-project.org>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	amadeuszx.slawinski@linux.intel.com,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ranjani Sridharan" <ranjani.sridharan@linux.intel.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
	"Bard Liao" <yung-chuan.liao@linux.intel.com>
Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32()
Date: Tue, 12 Jul 2022 15:51:04 +0200	[thread overview]
Message-ID: <2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com> (raw)
In-Reply-To: <YsnoH64cKCT7gndw@smile.fi.intel.com>



On 2022-07-09 10:42 PM, Andy Shevchenko wrote:
> On Sat, Jul 09, 2022 at 10:45:49AM +0200, Cezary Rojewski wrote:
>> On 2022-07-08 6:49 PM, Andy Shevchenko wrote:
>>> On Fri, Jul 8, 2022 at 6:32 PM Cezary Rojewski
>>> <cezary.rojewski@intel.com> wrote:
>>>>
>>>> On 2022-07-08 5:25 PM, Andy Shevchenko wrote:
>>>>> On Fri, Jul 8, 2022 at 2:34 PM Péter Ujfalusi
>>>>> <peter.ujfalusi@linux.intel.com> wrote:
>>>
>>>> A long shot, but what if we were to modify get_options() so it takes
>>>> additional element-size parameter instead?
>>>
>>> But why? int / unsigned int, u32 / s32  are all compatible in the current cases.
>>
>> I'd like to avoid any additional operations, so that the retrieved payload
>> can be provided to the IPC handler directly. The IPC handlers for AudioDSP
>> drivers are expecting payload in u32s.
>>
>> // u32 **tkns, size_t *num_tkns as foo() arguments
>> // u32 *ints, int nints as locals
>>
>> 	get_options(buf, 0, &nints);
>> 	if (!nints) {
>> 		ret = -ENOENT;
>> 		goto free_buf;
>> 	}
>>
>> 	ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL);
>> 	if (!ints) {
>> 		ret = -ENOMEM;
>> 		goto free_buf;
>> 	}
>>
>> 	get_num_options(buf, nints + 1, ints, sizeof(*ints));
>>
>> 	*tkns = ints;
>> 	*num_tkns = nints;
>>
>> No additional operations in between. The intermediate IPC handler can later
>> refer to the actual payload via &tkns[1] before passing it to the generic
>> one.
>>
>> Casting int array into u32 array does not feel right, or perhaps I'm missing
>> something like in the doc case.
> 
> C standard.
> 
> int to unsigned int is not promoted. And standard says that "The rank of any
> unsigned integer type shall equal the rank of the corresponding signed integer
> type, if any."
> 
> I don't know why one needs to have an additional churn here. int and unsigned
> int are interoperable with the adjustment to the sign when the other argument
> is signed or lesser rank of.


I still believe that casting blindly is not the way to go. I did 
explicitly ask about int vs u32, not int vs unsigned int. Please note 
that these values are later passed to the IPC handlers, and this changes 
the context a bit. If hw expects u32, then u32 it shall be.

Please correct me if I'm wrong, but there is no guarantee that int is 
always 32bits long. What is guaranteed though, is that int holds at 
least -/+ 32,767. Also, values larger than INT_MAX are allowed in the 
IPC payload.


Regards,
Czarek

WARNING: multiple messages have this Message-ID (diff)
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Andy Shevchenko" <andy@kernel.org>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"ALSA Development Mailing List" <alsa-devel@alsa-project.org>,
	"Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Bard Liao" <yung-chuan.liao@linux.intel.com>,
	"Ranjani Sridharan" <ranjani.sridharan@linux.intel.com>,
	amadeuszx.slawinski@linux.intel.com,
	"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32()
Date: Tue, 12 Jul 2022 15:51:04 +0200	[thread overview]
Message-ID: <2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com> (raw)
In-Reply-To: <YsnoH64cKCT7gndw@smile.fi.intel.com>



On 2022-07-09 10:42 PM, Andy Shevchenko wrote:
> On Sat, Jul 09, 2022 at 10:45:49AM +0200, Cezary Rojewski wrote:
>> On 2022-07-08 6:49 PM, Andy Shevchenko wrote:
>>> On Fri, Jul 8, 2022 at 6:32 PM Cezary Rojewski
>>> <cezary.rojewski@intel.com> wrote:
>>>>
>>>> On 2022-07-08 5:25 PM, Andy Shevchenko wrote:
>>>>> On Fri, Jul 8, 2022 at 2:34 PM Péter Ujfalusi
>>>>> <peter.ujfalusi@linux.intel.com> wrote:
>>>
>>>> A long shot, but what if we were to modify get_options() so it takes
>>>> additional element-size parameter instead?
>>>
>>> But why? int / unsigned int, u32 / s32  are all compatible in the current cases.
>>
>> I'd like to avoid any additional operations, so that the retrieved payload
>> can be provided to the IPC handler directly. The IPC handlers for AudioDSP
>> drivers are expecting payload in u32s.
>>
>> // u32 **tkns, size_t *num_tkns as foo() arguments
>> // u32 *ints, int nints as locals
>>
>> 	get_options(buf, 0, &nints);
>> 	if (!nints) {
>> 		ret = -ENOENT;
>> 		goto free_buf;
>> 	}
>>
>> 	ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL);
>> 	if (!ints) {
>> 		ret = -ENOMEM;
>> 		goto free_buf;
>> 	}
>>
>> 	get_num_options(buf, nints + 1, ints, sizeof(*ints));
>>
>> 	*tkns = ints;
>> 	*num_tkns = nints;
>>
>> No additional operations in between. The intermediate IPC handler can later
>> refer to the actual payload via &tkns[1] before passing it to the generic
>> one.
>>
>> Casting int array into u32 array does not feel right, or perhaps I'm missing
>> something like in the doc case.
> 
> C standard.
> 
> int to unsigned int is not promoted. And standard says that "The rank of any
> unsigned integer type shall equal the rank of the corresponding signed integer
> type, if any."
> 
> I don't know why one needs to have an additional churn here. int and unsigned
> int are interoperable with the adjustment to the sign when the other argument
> is signed or lesser rank of.


I still believe that casting blindly is not the way to go. I did 
explicitly ask about int vs u32, not int vs unsigned int. Please note 
that these values are later passed to the IPC handlers, and this changes 
the context a bit. If hw expects u32, then u32 it shall be.

Please correct me if I'm wrong, but there is no guarantee that int is 
always 32bits long. What is guaranteed though, is that int holds at 
least -/+ 32,767. Also, values larger than INT_MAX are allowed in the 
IPC payload.


Regards,
Czarek

  reply	other threads:[~2022-07-12 13:51 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  9:13 [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32() Cezary Rojewski
2022-07-07  9:13 ` Cezary Rojewski
2022-07-07  9:13 ` [PATCH 2/2] ASoC: SOF: Remove tokenize_input() Cezary Rojewski
2022-07-07  9:13   ` Cezary Rojewski
2022-07-07 13:51 ` [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32() Péter Ujfalusi
2022-07-07 13:51   ` Péter Ujfalusi
2022-07-08 11:33   ` Cezary Rojewski
2022-07-08 11:33     ` Cezary Rojewski
2022-07-08 10:22 ` Andy Shevchenko
2022-07-08 10:22   ` Andy Shevchenko
2022-07-08 11:29   ` Andy Shevchenko
2022-07-08 11:29     ` Andy Shevchenko
2022-07-08 11:32   ` Cezary Rojewski
2022-07-08 11:32     ` Cezary Rojewski
2022-07-08 11:46     ` Andy Shevchenko
2022-07-08 11:46       ` Andy Shevchenko
2022-07-08 11:51       ` Andy Shevchenko
2022-07-08 11:51         ` Andy Shevchenko
2022-07-08 12:13       ` Cezary Rojewski
2022-07-08 12:13         ` Cezary Rojewski
2022-07-08 12:30         ` Andy Shevchenko
2022-07-08 12:30           ` Andy Shevchenko
2022-07-08 12:35           ` Péter Ujfalusi
2022-07-08 12:35             ` Péter Ujfalusi
2022-07-08 15:25             ` Andy Shevchenko
2022-07-08 15:25               ` Andy Shevchenko
2022-07-08 15:28               ` Andy Shevchenko
2022-07-08 15:28                 ` Andy Shevchenko
2022-07-08 16:32               ` Cezary Rojewski
2022-07-08 16:32                 ` Cezary Rojewski
2022-07-08 16:49                 ` Andy Shevchenko
2022-07-08 16:49                   ` Andy Shevchenko
2022-07-09  8:45                   ` Cezary Rojewski
2022-07-09  8:45                     ` Cezary Rojewski
2022-07-09 20:42                     ` Andy Shevchenko
2022-07-09 20:42                       ` Andy Shevchenko
2022-07-12 13:51                       ` Cezary Rojewski [this message]
2022-07-12 13:51                         ` Cezary Rojewski
2022-07-12 13:59                         ` Andy Shevchenko
2022-07-12 13:59                           ` Andy Shevchenko
2022-07-12 14:02                         ` Mark Brown
2022-07-12 14:02                           ` Mark Brown
2022-07-12 14:24                         ` Andy Shevchenko
2022-07-12 14:24                           ` Andy Shevchenko
2022-07-19 11:40                           ` Cezary Rojewski
2022-07-19 11:40                             ` Cezary Rojewski
2022-08-09  9:55                           ` Cezary Rojewski
2022-08-09  9:55                             ` Cezary Rojewski
2022-08-09 15:23                             ` Andy Shevchenko
2022-08-09 15:23                               ` Andy Shevchenko
2022-08-16  9:28                               ` Cezary Rojewski
2022-08-16  9:28                                 ` Cezary Rojewski
2022-08-25 15:09                                 ` Andy Shevchenko
2022-08-25 15:09                                   ` Andy Shevchenko
2022-08-25 16:44                                   ` Cezary Rojewski
2022-08-25 16:44                                     ` Cezary Rojewski
2022-07-13  9:14                 ` David Laight
2022-07-13  9:14                   ` David Laight
2022-07-13  9:38                   ` Andy Shevchenko
2022-07-13  9:38                     ` Andy Shevchenko

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=2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amadeuszx.slawinski@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.