Re: [PATCH v3] staging: r8188eu: Fix return type for implementation of ndo_start_xmit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is the list of bugs that Smatch found.  I had to modify the check a bit.

regards,
dan carpenter
/*
 * Copyright (C) 2022 Your Name.
 *
 * 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 struct symbol *get_enum_type(struct expression *expr)
{
	struct symbol *type;
	int test = 0;

	test++;
	type = get_final_type(expr);
	if (!type)
		goto out_debug;
	if (type->type == SYM_PTR) {
		test++;
		type = get_real_base_type(type);
	}

	test = 3;
	if (!type || type->type != SYM_FN)
		goto out_debug;

	test++;
	type = get_real_base_type(type);
	if (!type || type->type != SYM_ENUM)
		goto out_debug;

	return type;

out_debug:
	if (local_debug)
		sm_msg("%s: expr='%s' test=%d type='%s'", __func__, expr_to_str(expr), test, type_to_str(type));
	return NULL;
}

static bool enums_equiv(struct symbol *a, struct symbol *b)
{
	if (!a && !b)
		return true;
	if (!a || !b)
		return false;
	if (!a->ident && !b->ident)
		return types_equiv(a, b);
	if (!a->ident || !b->ident)
		return false;
	return strcmp(a->ident->name, b->ident->name) == 0;
}

static bool is_void(struct expression *expr)
{
	struct symbol *type = get_type(expr);

	return types_equiv(type, &void_ctype);
}

static void match_assign(struct expression *expr)
{
	struct symbol *left, *right;
	char *name;

	if (expr->op != '=')
		return;
	if (is_fake_call(expr->right))
		return;
	if (expr_is_zero(expr->right))
		return;

	left = get_enum_type(expr->left);
	right = get_enum_type(expr->right);
	if (enums_equiv(left, right))
		return;

	if (is_void_ptr(get_type(expr->left)) ||
	    is_void_ptr(get_type(expr->right)))
		return;

	// FIXME: what?
	if (is_void(expr->left))
		return;

	name = expr_to_str(expr);
	sm_warning("CLANG_CFI insists types match exactly: '%s' '%s vs %s'", name,
		   type_to_str(left), type_to_str(right));
	sm_msg("%s: left_type='%s'", __func__, type_to_str(get_type(expr->left)));
	free_string(name);
}

void check_enum_cfi(int id)
{
	my_id = id;

	add_hook(&match_assign, ASSIGNMENT_HOOK);
	add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);
}

Attachment: err-list
Description: Binary data


[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux