From: Ayush Singh <ayushdevel1325@gmail.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: greybus-dev@lists.linaro.org, johan@kernel.org, elder@kernel.org,
linux-kernel@vger.kernel.org, jkridner@beagleboard.org,
nm@ti.com, yujie.liu@intel.com
Subject: Re: [PATCH 1/1] greybus: gb-beagleplay: Remove use of pad bytes
Date: Thu, 7 Dec 2023 22:33:54 +0530 [thread overview]
Message-ID: <c0823649-8235-40d7-813e-8a4500251219@gmail.com> (raw)
In-Reply-To: <2023120758-coleslaw-unstopped-530c@gregkh>
>> + *
>> + * @cport: cport id
>> + * @hdr: greybus operation header
>> + * @payload: greybus message payload
>> + */
>> +struct hdlc_greybus_frame {
>> + __le16 cport;
>> + struct gb_operation_msg_hdr hdr;
>> + u8 payload[];
>> +} __packed;
>> +
>> static void hdlc_rx_greybus_frame(struct gb_beagleplay *bg, u8 *buf, u16 len)
>> {
>> - u16 cport_id;
>> - struct gb_operation_msg_hdr *hdr = (struct gb_operation_msg_hdr *)buf;
>> + struct hdlc_greybus_frame *gb_frame = (struct hdlc_greybus_frame *)buf;
>> + u16 cport_id = le16_to_cpu(gb_frame->cport);
>>
>> - memcpy(&cport_id, hdr->pad, sizeof(cport_id));
>> + /* Ensure that the greybus message is valid */
>> + if (le16_to_cpu(gb_frame->hdr.size) > len - sizeof(cport_id)) {
>> + dev_warn_ratelimited(&bg->sd->dev, "Invalid/Incomplete greybus message");
> Don't spam the kernel log for corrupted data on the line, that would be
> a mess. Use a tracepoint?
>
>> + return;
>> + }
>>
>> dev_dbg(&bg->sd->dev, "Greybus Operation %u type %X cport %u status %u received",
>> - hdr->operation_id, hdr->type, le16_to_cpu(cport_id), hdr->result);
>> + gb_frame->hdr.operation_id, gb_frame->hdr.type, cport_id, gb_frame->hdr.result);
> Better yet, put the error in the debug message?
Shouldn't corrupt data be a warning rather than debug message, since it
indicates something wrong with the transport?
>>
>> - greybus_data_rcvd(bg->gb_hd, le16_to_cpu(cport_id), buf, len);
>> + greybus_data_rcvd(bg->gb_hd, cport_id, &buf[sizeof(cport_id)],
> Fun with pointer math. This feels really fragile, why not just point to
> the field instead?
It seems that taking address of members of packed structures is not
valid. I get the `address-of-packed-member` warnings. Is it fine to
ignore those in kernel?
>> }
>>
>> static void hdlc_rx_dbg_frame(const struct gb_beagleplay *bg, const char *buf, u16 len)
>> @@ -339,7 +357,7 @@ static struct serdev_device_ops gb_beagleplay_ops = {
>> static int gb_message_send(struct gb_host_device *hd, u16 cport, struct gb_message *msg, gfp_t mask)
>> {
>> struct gb_beagleplay *bg = dev_get_drvdata(&hd->dev);
>> - struct hdlc_payload payloads[2];
>> + struct hdlc_payload payloads[3];
> why 3?
>
> It's ok to put this on the stack?
Well, the HDLC payload is just to store the length of the payload along
with a pointer to its data. (kind of emulate a fat pointer). The reason
for doing it this way is to avoid having to create a temp buffer for
each message when sending data over UART (which was done in the initial
version of the driver).
Ayush Singh
next prev parent reply other threads:[~2023-12-07 17:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 15:05 [PATCH 0/1] Make gb-beagleplay driver Greybus compliant Ayush Singh
2023-12-06 15:06 ` [PATCH 1/1] greybus: gb-beagleplay: Remove use of pad bytes Ayush Singh
2023-12-07 11:30 ` Greg KH
2023-12-07 17:03 ` Ayush Singh [this message]
2023-12-08 5:33 ` Greg KH
2023-12-08 8:22 ` Ayush Singh
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=c0823649-8235-40d7-813e-8a4500251219@gmail.com \
--to=ayushdevel1325@gmail.com \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=jkridner@beagleboard.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nm@ti.com \
--cc=yujie.liu@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.