Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
On 15/06/17, Jani Nikula wrote:
> On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> > On 15/06/17, Jani Nikula wrote:
> >> Separate declaration and initialization would lead to a cleaner patch
> >> and result.
> >
> > I saw combining declaration and initialization is quite common, i.e. in
> > drm_atomic file. Personally, I also prefer those in one statement. But yes, 
> > it
> > looks cleaner here, in two lines.
> 
> I'd say the rule of thumb is that combined declaration and
> initialization is fine if the initialization is trivial, in particular
> can never fail. If you need to check the return value, like in this
> case, I'd prefer separate initialization.
> 
Yeah, makes sense. If you need to check then it exceeds simple initialization,
and then it is not declare Yes, now I see it.

Thanks a lot,
Dawid

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
On 15/06/17, Jani Nikula wrote:
> On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> > On 15/06/17, Jani Nikula wrote:
> >> Separate declaration and initialization would lead to a cleaner patch
> >> and result.
> >
> > I saw combining declaration and initialization is quite common, i.e. in
> > drm_atomic file. Personally, I also prefer those in one statement. But yes, 
> > it
> > looks cleaner here, in two lines.
> 
> I'd say the rule of thumb is that combined declaration and
> initialization is fine if the initialization is trivial, in particular
> can never fail. If you need to check the return value, like in this
> case, I'd prefer separate initialization.
> 
Yeah, makes sense. If you need to check then it exceeds simple initialization,
and then it is not declare Yes, now I see it.

Thanks a lot,
Dawid

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Jani Nikula
On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> On 15/06/17, Jani Nikula wrote:
>> Separate declaration and initialization would lead to a cleaner patch
>> and result.
>
> I saw combining declaration and initialization is quite common, i.e. in
> drm_atomic file. Personally, I also prefer those in one statement. But yes, it
> looks cleaner here, in two lines.

I'd say the rule of thumb is that combined declaration and
initialization is fine if the initialization is trivial, in particular
can never fail. If you need to check the return value, like in this
case, I'd prefer separate initialization.

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center


Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Jani Nikula
On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> On 15/06/17, Jani Nikula wrote:
>> Separate declaration and initialization would lead to a cleaner patch
>> and result.
>
> I saw combining declaration and initialization is quite common, i.e. in
> drm_atomic file. Personally, I also prefer those in one statement. But yes, it
> looks cleaner here, in two lines.

I'd say the rule of thumb is that combined declaration and
initialization is fine if the initialization is trivial, in particular
can never fail. If you need to check the return value, like in this
case, I'd prefer separate initialization.

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Technology Center


Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
On 15/06/17, Jani Nikula wrote:
> On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> > Smaller scope reduces visibility of variable and makes usage of
> > uninitialized variable less possible.
> > ---
> >  drivers/gpu/drm/drm_atomic.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index f32506a..ea5a9a7 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -108,10 +108,11 @@ struct drm_atomic_state *
> >  drm_atomic_state_alloc(struct drm_device *dev)
> >  {
> > struct drm_mode_config *config = >mode_config;
> > -   struct drm_atomic_state *state;
> >  
> > if (!config->funcs->atomic_state_alloc) {
> > -   state = kzalloc(sizeof(*state), GFP_KERNEL);
> > +   struct drm_atomic_state *state
> > +   = kzalloc(sizeof(*state), GFP_KERNEL);
> 
> Separate declaration and initialization would lead to a cleaner patch
> and result.

I saw combining declaration and initialization is quite common, i.e. in
drm_atomic file. Personally, I also prefer those in one statement. But yes, it
looks cleaner here, in two lines.

v2 sent :)

Thanks,
Dawid

> 
> BR,
> Jani.
> 
> > +
> > if (!state)
> > return NULL;
> > if (drm_atomic_state_init(dev, state) < 0) {
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
On 15/06/17, Jani Nikula wrote:
> On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> > Smaller scope reduces visibility of variable and makes usage of
> > uninitialized variable less possible.
> > ---
> >  drivers/gpu/drm/drm_atomic.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index f32506a..ea5a9a7 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -108,10 +108,11 @@ struct drm_atomic_state *
> >  drm_atomic_state_alloc(struct drm_device *dev)
> >  {
> > struct drm_mode_config *config = >mode_config;
> > -   struct drm_atomic_state *state;
> >  
> > if (!config->funcs->atomic_state_alloc) {
> > -   state = kzalloc(sizeof(*state), GFP_KERNEL);
> > +   struct drm_atomic_state *state
> > +   = kzalloc(sizeof(*state), GFP_KERNEL);
> 
> Separate declaration and initialization would lead to a cleaner patch
> and result.

I saw combining declaration and initialization is quite common, i.e. in
drm_atomic file. Personally, I also prefer those in one statement. But yes, it
looks cleaner here, in two lines.

v2 sent :)

Thanks,
Dawid

> 
> BR,
> Jani.
> 
> > +
> > if (!state)
> > return NULL;
> > if (drm_atomic_state_init(dev, state) < 0) {
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Jani Nikula
On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> Smaller scope reduces visibility of variable and makes usage of
> uninitialized variable less possible.
> ---
>  drivers/gpu/drm/drm_atomic.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f32506a..ea5a9a7 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -108,10 +108,11 @@ struct drm_atomic_state *
>  drm_atomic_state_alloc(struct drm_device *dev)
>  {
>   struct drm_mode_config *config = >mode_config;
> - struct drm_atomic_state *state;
>  
>   if (!config->funcs->atomic_state_alloc) {
> - state = kzalloc(sizeof(*state), GFP_KERNEL);
> + struct drm_atomic_state *state
> + = kzalloc(sizeof(*state), GFP_KERNEL);

Separate declaration and initialization would lead to a cleaner patch
and result.

BR,
Jani.

> +
>   if (!state)
>   return NULL;
>   if (drm_atomic_state_init(dev, state) < 0) {

-- 
Jani Nikula, Intel Open Source Technology Center


Re: [PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Jani Nikula
On Thu, 15 Jun 2017, Dawid Kurek  wrote:
> Smaller scope reduces visibility of variable and makes usage of
> uninitialized variable less possible.
> ---
>  drivers/gpu/drm/drm_atomic.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index f32506a..ea5a9a7 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -108,10 +108,11 @@ struct drm_atomic_state *
>  drm_atomic_state_alloc(struct drm_device *dev)
>  {
>   struct drm_mode_config *config = >mode_config;
> - struct drm_atomic_state *state;
>  
>   if (!config->funcs->atomic_state_alloc) {
> - state = kzalloc(sizeof(*state), GFP_KERNEL);
> + struct drm_atomic_state *state
> + = kzalloc(sizeof(*state), GFP_KERNEL);

Separate declaration and initialization would lead to a cleaner patch
and result.

BR,
Jani.

> +
>   if (!state)
>   return NULL;
>   if (drm_atomic_state_init(dev, state) < 0) {

-- 
Jani Nikula, Intel Open Source Technology Center


[PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
Smaller scope reduces visibility of variable and makes usage of
uninitialized variable less possible.
---
 drivers/gpu/drm/drm_atomic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index f32506a..ea5a9a7 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -108,10 +108,11 @@ struct drm_atomic_state *
 drm_atomic_state_alloc(struct drm_device *dev)
 {
struct drm_mode_config *config = >mode_config;
-   struct drm_atomic_state *state;
 
if (!config->funcs->atomic_state_alloc) {
-   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   struct drm_atomic_state *state
+   = kzalloc(sizeof(*state), GFP_KERNEL);
+
if (!state)
return NULL;
if (drm_atomic_state_init(dev, state) < 0) {
-- 
2.10.0


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



[PATCH] drm: Reduce scope of 'state' variable

2017-06-15 Thread Dawid Kurek
Smaller scope reduces visibility of variable and makes usage of
uninitialized variable less possible.
---
 drivers/gpu/drm/drm_atomic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index f32506a..ea5a9a7 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -108,10 +108,11 @@ struct drm_atomic_state *
 drm_atomic_state_alloc(struct drm_device *dev)
 {
struct drm_mode_config *config = >mode_config;
-   struct drm_atomic_state *state;
 
if (!config->funcs->atomic_state_alloc) {
-   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   struct drm_atomic_state *state
+   = kzalloc(sizeof(*state), GFP_KERNEL);
+
if (!state)
return NULL;
if (drm_atomic_state_init(dev, state) < 0) {
-- 
2.10.0


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus