All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Alex Elder <alex.elder@linaro.org>
Cc: elder@linaro.org, kernel-janitors@vger.kernel.org
Subject: Re: [bug report] net: ipa: reduce arguments to ipa_table_init_add()
Date: Thu, 17 Nov 2022 07:47:27 +0300	[thread overview]
Message-ID: <Y3W83708rvg1Krvy@kadam> (raw)
In-Reply-To: <b30d04f4-db62-6a65-f35b-de7b979e5e65@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 902 bytes --]

On Tue, Nov 15, 2022 at 11:00:49AM -0600, Alex Elder wrote:
> > drivers/net/ipa/ipa_table.c
> >     413			count = mem->size / sizeof(__le64);
> >     414			hash_count = hash_mem && hash_mem->size / sizeof(__le64);
> 
> Line 414 is wrong.  It should be:
>     hash_count = hash_mem ? hash_mem->size / sizeof(__le64) : 0;
> 

Heh.  It really feels like this line should have generated a checker
warning as well.  I've created two versions.  The first complains when
ever there is a divide used as a condition:

	if (a / b) {

The other complains when it's part of a logical && or ||.

	if (a && a / b) {

drivers/net/ipa/ipa_table.c:414 ipa_table_init_add() warn: divide condition: 'hash_mem->size / 8'
drivers/net/ipa/ipa_table.c:414 ipa_table_init_add() warn: divide condition (logical): 'hash_mem->size / 8'

I'll test them out tonight and see if either gives useful results.

regards,
dan carpenter


[-- Attachment #2: check_divide_condition.c --]
[-- Type: text/x-csrc, Size: 1604 bytes --]

/*
 * Copyright (C) 2022 Dan Carpenter.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
 */

#include "smatch.h"
#include "smatch_extra.h"

static int my_id;

static void match_condition1(struct expression *expr)
{
	char *name;

	if (expr->type != EXPR_BINOP || expr->op != '/')
		return;

	name = expr_to_str(expr);
	sm_warning("divide condition: '%s'", name);
	free_string(name);
}

static void match_condition2(struct expression *expr)
{
	struct expression *parent;
	char *name;

	if (expr->type != EXPR_BINOP || expr->op != '/')
		return;

	parent = expr_get_parent_expr(expr);
	while (parent && parent->type == EXPR_PREOP && parent->op == '(')
		parent = expr_get_parent_expr(parent);

	if (!parent || parent->type != EXPR_LOGICAL)
		return;

	name = expr_to_str(expr);
	sm_warning("divide condition (logical): '%s'", name);
	free_string(name);
}

void check_divide_condition(int id)
{
	my_id = id;

	add_hook(&match_condition1, CONDITION_HOOK);
	add_hook(&match_condition2, CONDITION_HOOK);

}

  reply	other threads:[~2022-11-17  4:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 13:03 [bug report] net: ipa: reduce arguments to ipa_table_init_add() Dan Carpenter
2022-11-15 17:00 ` Alex Elder
2022-11-17  4:47   ` Dan Carpenter [this message]
2022-11-18  9:50     ` Dan Carpenter
2022-11-19  9:21       ` Alex Elder
2022-11-19 10:48         ` Dan Carpenter
2022-11-19  9:04     ` Alex Elder

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=Y3W83708rvg1Krvy@kadam \
    --to=error27@gmail.com \
    --cc=alex.elder@linaro.org \
    --cc=elder@linaro.org \
    --cc=kernel-janitors@vger.kernel.org \
    /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.