Skip to contentSkip to conversation

NFC: smatch stuff: min_t() casting

DISCUSSION Dan Carpenter 1 participant 1 message Dec 16, 2011

lore
Share & tools
lore
#0 lore raw

Hi Sam,

Smatch complains about the min_t() casting here.

net/nfc/llcp/sock.c +80 llcp_sock_bind(44)

	warn: min_t truncates here '(llcp_addr.service_name_len)' (4294967295 vs 9223372036854775807)

    78          llcp_sock->local = local;
    79          llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
    80          llcp_sock->service_name_len = min_t(unsigned int,
    81                          llcp_addr.service_name_len, NFC_LLCP_MAX_SERVICE_NAME);
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^

Smatch complains that .service_name_len is a size_t (64 bits on 64 bit architectures). The cast to unsigned int takes the minimum of the truncated value.

    82          llcp_sock->service_name = kmemdup(llcp_addr.service_name,
    83                                  llcp_sock->service_name_len, GFP_KERNEL);

These two functions are the same way.

net/nfc/llcp/sock.c +461 llcp_sock_connect(71)

	warn: min_t truncates here '(addr->service_name_len)' (4294967295 vs 9223372036854775807)
net/nfc/llcp/sock.c +521 llcp_sock_recvmsg(36) warn:
	min_t truncates here '(len)' (4294967295 vs 9223372036854775807)

It's not really an issue, but it's slightly untidy.

regards,
dan carpenter