From: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: vasily.isaenko@oracle.com
Subject: Re: [PATCH V2 2/4] ofnet: move the allocation of the transmit buffer into a function
Date: Mon, 12 Dec 2016 13:38:27 +0300 [thread overview]
Message-ID: <584E7E23.4000501@oracle.com> (raw)
In-Reply-To: <CAA91j0UwrGJiroY7Cvrux0CXO6253fCmVi7QByhTM1uhmUhN=A@mail.gmail.com>
On 12/12/2016 01:27 PM, Andrei Borzenkov wrote:
> While I agree with your reasons, it belongs to separate commit, and
> definitely is out of place if you say in commit message "I'm moving
> piece of code". Actually, it is not related to this patch series, so
> feel free to send this cleanup as separate patch.
Thank you. I'll stick to 'return 0' for this series.
>
> On Mon, Dec 12, 2016 at 12:47 PM, Stanislav Kholmanskikh
> <stanislav.kholmanskikh@oracle.com> wrote:
>>
>>
>> On 12/05/2016 06:52 PM, Daniel Kiper wrote:
>>> On Fri, Dec 02, 2016 at 06:10:03PM +0300, Stanislav Kholmanskikh wrote:
>>>> In the current code search_net_devices() uses the "alloc-mem" command
>>>> from the IEEE1275 User Interface for allocation of the transmit buffer
>>>> for the case when GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN is set.
>>>>
>>>> I don't have hardware where this flag is set to verify if this
>>>> workaround is still needed. However, further changes to ofnet will
>>>> require to execute this workaround one more time. Therefore, to
>>>> avoid possible duplication of code I'm moving this piece of
>>>> code into a function.
>>>>
>>>> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
>>>> ---
>>>> grub-core/net/drivers/ieee1275/ofnet.c | 71 ++++++++++++++++++++------------
>>>> 1 files changed, 44 insertions(+), 27 deletions(-)
>>>>
>>>> diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c
>>>> index 8332d34..25559c8 100644
>>>> --- a/grub-core/net/drivers/ieee1275/ofnet.c
>>>> +++ b/grub-core/net/drivers/ieee1275/ofnet.c
>>>> @@ -298,6 +298,48 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path,
>>>> }
>>>> }
>>>>
>>>> +/* Allocate memory with alloc-mem */
>>>> +static void *
>>>> +grub_ieee1275_alloc_mem (grub_size_t len)
>>>> +{
>>>> + struct alloc_args
>>>> + {
>>>> + struct grub_ieee1275_common_hdr common;
>>>> + grub_ieee1275_cell_t method;
>>>> + grub_ieee1275_cell_t len;
>>>> + grub_ieee1275_cell_t catch;
>>>> + grub_ieee1275_cell_t result;
>>>> + }
>>>> + args;
>>>> +
>>>> + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET))
>>>> + {
>>>> + grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("interpret is not supported"));
>>>> + return NULL;
>>>> + }
>>>> +
>>>> + INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2);
>>>> + args.len = len;
>>>> + args.method = (grub_ieee1275_cell_t) "alloc-mem";
>>>> +
>>>> + if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch)
>>>> + {
>>>> + grub_error (GRUB_ERR_INVALID_COMMAND, N_("alloc-mem failed"));
>>>> + return NULL;
>>>> + }
>>>> + else
>>>> + return (void *)args.result;
>>>> +}
>>>> +
>>>> +static void *
>>>> +ofnet_alloc_netbuf (grub_size_t len)
>>>> +{
>>>> + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN))
>>>> + return grub_ieee1275_alloc_mem (len);
>>>> + else
>>>> + return grub_zalloc (len);
>>>> +}
>>>> +
>>>> static int
>>>> search_net_devices (struct grub_ieee1275_devalias *alias)
>>>> {
>>>> @@ -414,39 +456,14 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
>>>>
>>>> card->txbufsize = ALIGN_UP (card->mtu, 64) + 256;
>>>>
>>>> - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN))
>>>> - {
>>>> - struct alloc_args
>>>> - {
>>>> - struct grub_ieee1275_common_hdr common;
>>>> - grub_ieee1275_cell_t method;
>>>> - grub_ieee1275_cell_t len;
>>>> - grub_ieee1275_cell_t catch;
>>>> - grub_ieee1275_cell_t result;
>>>> - }
>>>> - args;
>>>> - INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2);
>>>> - args.len = card->txbufsize;
>>>> - args.method = (grub_ieee1275_cell_t) "alloc-mem";
>>>> -
>>>> - if (IEEE1275_CALL_ENTRY_FN (&args) == -1
>>>> - || args.catch)
>>>> - {
>>>> - card->txbuf = 0;
>>>> - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
>>>> - }
>>>> - else
>>>> - card->txbuf = (void *) args.result;
>>>> - }
>>>> - else
>>>> - card->txbuf = grub_zalloc (card->txbufsize);
>>>> + card->txbuf = ofnet_alloc_netbuf (card->txbufsize);
>>>> if (!card->txbuf)
>>>> {
>>>> grub_free (ofdata->path);
>>>> grub_free (ofdata);
>>>> grub_free (card);
>>>> grub_print_error ();
>>>> - return 0;
>>>> + return 1;
>>>
>>> Hmmm... This looks like an error...
>>
>> Look, here is what I see.
>>
>> The search_net_devices() function is called from grub_ofnet_findcards() as:
>>
>> grub_ieee1275_devices_iterate (search_net_devices);
>>
>> The grub_ieee1275_devices_iterate(hook) function is defined in
>> grub-core/kern/ieee1275/openfw.c and what it does is basically calling
>> the hook for each IEEE1275 device in the tree until:
>> a) there are no more devices
>> b) the hook returns a value != 1
>>
>> So if search_net_devices() returns 1 it means that further probing for
>> network cards is stopped.
>>
>> I think that stopping further probes when a memory allocation function
>> fails is fine and it aligns with the existing code at the top of the
>> function, i.e. handling of the cases when allocating memory for 'card'
>> and 'ofdata' fails.
>>
>> If I'm not mistaken, we may also need to update the block:
>>
>> if (need_suffix)
>> ofdata->path = grub_malloc (grub_strlen (alias->path) + sizeof
>> (SUFFIX));
>> else
>> ofdata->path = grub_malloc (grub_strlen (alias->path) + 1);
>> if (!ofdata->path)
>> {
>> grub_print_error ();
>> return 0;
>> }
>>
>> and add a 'return 1' + free some memory there.
>>
>> As for the other block:
>>
>> pprop = (grub_uint8_t *) ∝
>> if (grub_ieee1275_get_property (devhandle, "mac-address",
>> pprop, sizeof(prop), &prop_size)
>> && grub_ieee1275_get_property (devhandle, "local-mac-address",
>> pprop, sizeof(prop), &prop_size))
>> {
>> grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
>> grub_print_error ();
>> return 0;
>> }
>>
>> it seems we need to add free memory procedures here as well, but I'm not
>> sure we need to return 1 here.
>>
>>
>>
>>>
>>> Daniel
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
next prev parent reply other threads:[~2016-12-12 10:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-02 15:10 [V2] Implementing the receive buffer for ofnet Stanislav Kholmanskikh
2016-12-02 15:10 ` [PATCH V2 1/4] ofnet: add error check for grub_netbuff_reserve Stanislav Kholmanskikh
2016-12-05 15:49 ` Daniel Kiper
2016-12-10 18:08 ` Andrei Borzenkov
2016-12-12 10:34 ` Stanislav Kholmanskikh
2016-12-12 12:10 ` Andrei Borzenkov
2016-12-02 15:10 ` [PATCH V2 2/4] ofnet: move the allocation of the transmit buffer into a function Stanislav Kholmanskikh
2016-12-05 15:52 ` Daniel Kiper
2016-12-12 9:47 ` Stanislav Kholmanskikh
2016-12-12 10:27 ` Andrei Borzenkov
2016-12-12 10:38 ` Stanislav Kholmanskikh [this message]
2016-12-02 15:10 ` [PATCH V2 3/4] ofnet: free memory on module unload Stanislav Kholmanskikh
2016-12-05 16:02 ` Daniel Kiper
2016-12-10 18:18 ` Andrei Borzenkov
2016-12-12 9:56 ` Stanislav Kholmanskikh
2016-12-02 15:10 ` [PATCH V2 4/4] ofnet: implement the receive buffer Stanislav Kholmanskikh
2016-12-05 16:12 ` Daniel Kiper
2016-12-10 18:29 ` Andrei Borzenkov
2016-12-10 19:50 ` Mark Otto
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=584E7E23.4000501@oracle.com \
--to=stanislav.kholmanskikh@oracle.com \
--cc=grub-devel@gnu.org \
--cc=vasily.isaenko@oracle.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).