linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: Hans de Goede <hdegoede@redhat.com>, linux-kernel@vger.kernel.org
Cc: "Mark Gross" <mgross@linux.intel.com>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Barnabás Pőcze" <pobrn@protonmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Blaž Hrastnik" <blaz@mxxn.io>,
	"Dorian Stoll" <dorian.stoll@tmsp.io>,
	platform-driver-x86@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v2 8/9] platform/surface: Add Surface Aggregator user-space interface
Date: Tue, 15 Dec 2020 21:00:16 +0100	[thread overview]
Message-ID: <a22def75-a4e5-4ae4-f527-7695630be1ee@gmail.com> (raw)
In-Reply-To: <13b24eb0-e60f-e1d6-fcea-a19f62c40b4f@redhat.com>

On 12/15/20 5:35 PM, Hans de Goede wrote:
> Hi,
> 
> On 12/3/20 10:26 PM, Maximilian Luz wrote:
>> Add a misc-device providing user-space access to the Surface Aggregator
>> EC, mainly intended for debugging, testing, and reverse-engineering.
>> This interface gives user-space applications the ability to send
>> requests to the EC and receive the corresponding responses.
>>
>> The device-file is managed by a pseudo platform-device and corresponding
>> driver to avoid dependence on the dedicated bus, allowing it to be
>> loaded in a minimal configuration.
>>
>> Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
> 
> 1 review comment inline:
>

[...]

>> +static long ssam_cdev_request(struct ssam_cdev *cdev, unsigned long arg)
>> +{
>> +	struct ssam_cdev_request __user *r;
>> +	struct ssam_cdev_request rqst;
>> +	struct ssam_request spec;
>> +	struct ssam_response rsp;
>> +	const void __user *plddata;
>> +	void __user *rspdata;
>> +	int status = 0, ret = 0, tmp;
>> +
>> +	r = (struct ssam_cdev_request __user *)arg;
>> +	ret = copy_struct_from_user(&rqst, sizeof(rqst), r, sizeof(*r));
>> +	if (ret)
>> +		goto out;
>> +
>> +	plddata = u64_to_user_ptr(rqst.payload.data);
>> +	rspdata = u64_to_user_ptr(rqst.response.data);
>> +
>> +	/* Setup basic request fields. */
>> +	spec.target_category = rqst.target_category;
>> +	spec.target_id = rqst.target_id;
>> +	spec.command_id = rqst.command_id;
>> +	spec.instance_id = rqst.instance_id;
>> +	spec.flags = rqst.flags;
>> +	spec.length = rqst.payload.length;
>> +	spec.payload = NULL;
>> +
>> +	rsp.capacity = rqst.response.length;
>> +	rsp.length = 0;
>> +	rsp.pointer = NULL;
>> +
>> +	/* Get request payload from user-space. */
>> +	if (spec.length) {
>> +		if (!plddata) {
>> +			ret = -EINVAL;
>> +			goto out;
>> +		}
>> +
>> +		spec.payload = kzalloc(spec.length, GFP_KERNEL);
>> +		if (!spec.payload) {
>> +			status = -ENOMEM;
>> +			ret = -EFAULT;
>> +			goto out;
>> +		}
>> +
>> +		if (copy_from_user((void *)spec.payload, plddata, spec.length)) {
>> +			ret = -EFAULT;
>> +			goto out;
>> +		}
>> +	}
>> +
>> +	/* Allocate response buffer. */
>> +	if (rsp.capacity) {
>> +		if (!rspdata) {
>> +			ret = -EINVAL;
>> +			goto out;
>> +		}
>> +
>> +		rsp.pointer = kzalloc(rsp.capacity, GFP_KERNEL);
>> +		if (!rsp.pointer) {
>> +			status = -ENOMEM;
>> +			ret = -EFAULT;
> 
> This is weird, -EFAULT should only be used if a SEGFAULT
> would have been raised if the code was running in
> userspace rather then in kernelspace, IOW if userspace
> has provided an invalid pointer (or a too small buffer,
> causing the pointer to become invalid at some point in
> the buffer).

Oh, right.

> IMHO you should simply do ret = -ENOMEM here.

Yes. that looks better. I will change that as suggested.
> Otherwise this looks good to me.

Thanks,
Max

  reply	other threads:[~2020-12-15 20:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 21:26 [PATCH v2 0/9] Add support for Microsoft Surface System Aggregator Module Maximilian Luz
2020-12-03 21:26 ` [PATCH v2 7/9] docs: driver-api: Add Surface Aggregator subsystem documentation Maximilian Luz
2020-12-15 16:25   ` Hans de Goede
2020-12-03 21:26 ` [PATCH v2 8/9] platform/surface: Add Surface Aggregator user-space interface Maximilian Luz
2020-12-15 16:35   ` Hans de Goede
2020-12-15 20:00     ` Maximilian Luz [this message]
2020-12-03 21:26 ` [PATCH v2 9/9] platform/surface: Add Surface ACPI Notify driver Maximilian Luz
2020-12-15 17:18   ` Hans de Goede
2020-12-06  7:07 ` [PATCH v2 0/9] Add support for Microsoft Surface System Aggregator Module Leon Romanovsky
2020-12-06  8:32   ` Greg Kroah-Hartman
2020-12-06  8:35     ` Leon Romanovsky
2020-12-06 11:13     ` Maximilian Luz
2020-12-06  8:41   ` Hans de Goede
2020-12-06  8:56     ` Leon Romanovsky
2020-12-06 10:04       ` Hans de Goede
2020-12-06 10:33         ` Leon Romanovsky
2020-12-06 10:41           ` Hans de Goede
2020-12-06 11:41             ` Leon Romanovsky
2020-12-06 13:43               ` Maximilian Luz
2020-12-06 10:51         ` Maximilian Luz
2020-12-06  8:58     ` Blaž Hrastnik
2020-12-06  9:06       ` Leon Romanovsky
2020-12-06 10:33         ` Maximilian Luz
2020-12-06 10:43           ` Hans de Goede
2020-12-06 10:56             ` Maximilian Luz
2020-12-06 11:30           ` Leon Romanovsky
2020-12-06 13:27             ` Maximilian Luz
2020-12-06 15:58   ` Maximilian Luz
2020-12-07  6:15     ` Leon Romanovsky
2020-12-07  8:49     ` Hans de Goede
2020-12-07  9:12       ` Greg Kroah-Hartman

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=a22def75-a4e5-4ae4-f527-7695630be1ee@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=blaz@mxxn.io \
    --cc=corbet@lwn.net \
    --cc=dorian.stoll@tmsp.io \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=pobrn@protonmail.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 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).