mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kys@microsoft.com, Stephen Hemminger <stephen@networkplumber.org>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
	vkuznets@redhat.com, jasowang@redhat.com,
	leann.ogasawara@canonical.com, marcelo.cerri@canonical.com,
	sthemmin@microsoft.com, Michael Kelley <mikelley@microsoft.com>
Subject: Re: [PATCH 08/12] Drivers: hv: vmbus: Implement Direct Mode for stimer0
Date: Mon, 12 Feb 2018 11:42:05 +0300	[thread overview]
Message-ID: <20180212084205.idjf2lwrdn2nprw7@mwanda> (raw)
In-Reply-To: <20180212003320.6748-8-kys@exchange.microsoft.com>

On Sun, Feb 11, 2018 at 05:33:16PM -0700, kys@exchange.microsoft.com wrote:
> @@ -116,9 +146,29 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt)
>  {
>  	union hv_timer_config timer_cfg;
>  
> +	timer_cfg.as_uint64 = 0;
>  	timer_cfg.enable = 1;
>  	timer_cfg.auto_enable = 1;
> -	timer_cfg.sintx = VMBUS_MESSAGE_SINT;
> +	if (direct_mode_enabled)
> +		/*
> +		 * When it expires, the timer will directly interrupt
> +		 * on the specified hardware vector/IRQ.
> +		 */
> +		{
> +		timer_cfg.direct_mode = 1;
> +		timer_cfg.apic_vector = stimer0_vector;
> +		hv_enable_stimer0_percpu_irq(stimer0_irq);
> +		}
> +	else
> +		/*
> +		 * When it expires, the timer will generate a VMbus message,
> +		 * to be handled by the normal VMbus interrupt handler.
> +		 */
> +		{
> +		timer_cfg.direct_mode = 0;
> +		timer_cfg.sintx = VMBUS_MESSAGE_SINT;
> +		}
> +

This indenting isn't right.  We should probably zero out .apic_vector
if .direct_mode is zero.  Or maybe it's fine.  I don't know if any
static analysis tools will complain...

>  	hv_init_timer_config(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
>  
>  	return 0;
> @@ -191,6 +241,10 @@ int hv_synic_alloc(void)
>  		INIT_LIST_HEAD(&hv_cpu->chan_list);
>  	}
>  
> +	if (direct_mode_enabled && hv_setup_stimer0_irq(
> +		&stimer0_irq, &stimer0_vector, hv_stimer0_isr))
> +		goto err;


Can you indent it like this:

	if (direct_mode_enabled &&
	    hv_setup_stimer0_irq(&stimer0_irq, &stimer0_vector,
				 hv_stimer0_isr))
		goto err;


[ What follows is a long rant not directed at you ]

It's annoying because as soon as I see the "goto err;", I know the error
handling for this function is going to be buggy...

Some rules of error handling are:

1)  Each function should clean up after itself instead returning
    partially allocated structures.
2)  Each allocation function should have a matching free function.
3)  Give meaningful label names based on what the label location so that
    we can tell what the goto does just by looking at it, such as,
    "goto free_some_variable".  This way we can just keep a mental tally
    of the most recently allocated resource and verify based on the
    "goto free_resource;" statemetn that it frees the correct thing.  We
    don't need to scroll to the bottom of the function.

    Using good names means that we should avoid do-nothing gotos
    because, by definition, the label name for a do-nothing goto is
    going to be vague.

In this case the label looks like this:

> +
>  	return 0;
>  err:
>  	return -ENOMEM;

We allocate a bunch of stuff in this function so at first glance this
looks like we leak everything but, actually, the cleanup is done in
vmbus_bus_init().  This is a layering violation.

Later on, we changed hv_synic_alloc() in 37cdd991fac8 ("vmbus: put
related per-cpu variable together") and we started allocating:

	hv_cpu->clk_evt = kzalloc(...

but we forgot to update the error handling because it was in the wrong
place.  It's a very predictable, avoidable bug if we just use proper
error handling style.

Anyway...  Sorry for the long rant.  Summary:  Always distrust vague
label names.

regards,
dan carpenter

  reply	other threads:[~2018-02-12  8:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12  0:29 [PATCH 00/12] Drivers: hv: Miscellaneous fixes kys
2018-02-12  0:33 ` [PATCH 01/12] tools/hv: Fix IP reporting by KVP daemon with SRIOV kys
2018-02-12  0:33   ` [PATCH 02/12] hyper-v: use GFP_KERNEL for hv_context.hv_numa_map kys
2018-02-12  0:33   ` [PATCH 03/12] hv: Synthetic typo correction kys
2018-02-12  0:33   ` [PATCH 04/12] tools: hv: fix compiler warnings about major/target_fname kys
2018-02-12  0:33   ` [PATCH 05/12] tools: hv: include string.h in hv_fcopy_daemon kys
2018-02-12  0:33   ` [PATCH 06/12] vmbus/ring_buffer: remove some redundant helper function kys
2018-02-12  0:33   ` [PATCH 07/12] hv_vmbus: Correct the stale comments regarding cpu affinity kys
2018-02-12  0:33   ` [PATCH 08/12] Drivers: hv: vmbus: Implement Direct Mode for stimer0 kys
2018-02-12  8:42     ` Dan Carpenter [this message]
2018-02-14  2:58       ` Michael Kelley (EOSG)
2018-02-14  7:34         ` Dan Carpenter
2018-02-12  0:33   ` [PATCH 09/12] hv_balloon: fix printk loglevel kys
2018-02-12  0:33   ` [PATCH 10/12] hv_balloon: simplify hv_online_page()/hv_page_online_one() kys
2018-02-12  0:33   ` [PATCH 11/12] hv_balloon: fix bugs in num_pages_onlined accounting kys
2018-02-12  0:38 ` [PATCH 12/12] hv_balloon: trace post_status kys

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=20180212084205.idjf2lwrdn2nprw7@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=leann.ogasawara@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.cerri@canonical.com \
    --cc=mikelley@microsoft.com \
    --cc=olaf@aepfle.de \
    --cc=stephen@networkplumber.org \
    --cc=sthemmin@microsoft.com \
    --cc=vkuznets@redhat.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

all inboxes | Powered by JetHome®