Skip to content

Commit

Permalink
Add checkpatch.conf and apply checkpatch fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Michalis Pappas <[email protected]>
  • Loading branch information
michpappas authored and jbech-linaro committed May 22, 2018
1 parent 21747e3 commit 2ec8783
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 24 deletions.
22 changes: 22 additions & 0 deletions .checkpatch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2017, Linaro Ltd and contributors
# SPDX-License-Identifier: Apache-2.0
#

# Do not expect a Linux tree
--no-tree

# Allow lines up to 90 characters long
--max-line-length=90

# Show the filename at the top of each report.
# Makes reports easier to read.
--showfile

# Show terse reports
--quiet

# The Linux kernel uses C++ style comments for the SPDX identifier
# We don't use the same comment format in Secure96
--ignore SPDX_LICENSE_TAG

26 changes: 13 additions & 13 deletions s96at/include/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum {
};

#define ZONE_CONFIG_SIZE 88
#define ZONE_OTP_SIZE 64
#define ZONE_OTP_SIZE 64
#define ZONE_DATA_SIZE 512

#define ZONE_CONFIG_NUM_WORDS 22
Expand Down Expand Up @@ -64,19 +64,19 @@ enum {

/* OP-codes for each command, see section 8.5.4 in spec */
#define OPCODE_DERIVEKEY 0x1c
#define OPCODE_DEVREV 0x30
#define OPCODE_GENDIG 0x15
#define OPCODE_HMAC 0x11
#define OPCODE_DEVREV 0x30
#define OPCODE_GENDIG 0x15
#define OPCODE_HMAC 0x11
#define OPCODE_CHECKMAC 0x28
#define OPCODE_LOCK 0x17
#define OPCODE_MAC 0x08
#define OPCODE_NONCE 0x16
#define OPCODE_PAUSE 0x01
#define OPCODE_RANDOM 0x1b
#define OPCODE_READ 0x02
#define OPCODE_SHA 0x47
#define OPCODE_UPDATEEXTRA 0x20
#define OPCODE_WRITE 0x12
#define OPCODE_LOCK 0x17
#define OPCODE_MAC 0x08
#define OPCODE_NONCE 0x16
#define OPCODE_PAUSE 0x01
#define OPCODE_RANDOM 0x1b
#define OPCODE_READ 0x02
#define OPCODE_SHA 0x47
#define OPCODE_UPDATEEXTRA 0x20
#define OPCODE_WRITE 0x12

/* Addresses etc for the configuration zone. */
#define OTP_CONFIG_ADDR 0x4
Expand Down
2 changes: 1 addition & 1 deletion s96at/include/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cmd.h>

#define CRC_LEN 2 /* In bytes */
#define CRC_POLYNOM 0x8005
#define CRC_POLYNOM 0x8005

bool crc_valid(const uint8_t *data, uint8_t *crc, size_t data_len);
uint16_t get_packet_crc(struct cmd_packet *p, size_t payload_size);
Expand Down
8 changes: 4 additions & 4 deletions s96at/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#ifdef DEBUG
#define logd(fmt, ...) \
fprintf(stdout, fmt, ##__VA_ARGS__);
fprintf(stdout, fmt, ##__VA_ARGS__)

#define loge(fmt, ...) \
fprintf(stderr, fmt, ##__VA_ARGS__);
fprintf(stderr, fmt, ##__VA_ARGS__)
#else
#define logd(fmt, ...)
#define loge(fmt, ...)
Expand All @@ -25,10 +25,10 @@

#ifdef DEBUG
#define logd(fmt, ...) \
fprintf(stdout, "[%s : %d]: " fmt, __func__, __LINE__, ##__VA_ARGS__);
fprintf(stdout, "[%s : %d]: " fmt, __func__, __LINE__, ##__VA_ARGS__)

#define loge(fmt, ...) \
fprintf(stderr, "[%s : %d]: " fmt, __func__, __LINE__, ##__VA_ARGS__);
fprintf(stderr, "[%s : %d]: " fmt, __func__, __LINE__, ##__VA_ARGS__)
#else
#define logd(fmt, ...)
#endif
Expand Down
4 changes: 2 additions & 2 deletions s96at/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
uint8_t SLOT_CONFIG_ADDR(uint8_t slotnbr)
{
uint8_t addr = 0x5;

if (slotnbr % 2)
slotnbr--;
slotnbr >>= 1;
Expand All @@ -39,8 +40,7 @@ void get_command(struct cmd_packet *p, uint8_t opcode)
p->data = NULL;
p->data_length = 0;

switch (p->opcode)
{
switch (p->opcode) {
case OPCODE_DERIVEKEY:
p->max_time = 62; /* Table 8.4 */
break;
Expand Down
1 change: 1 addition & 0 deletions s96at/src/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
bool crc_valid(const uint8_t *data, uint8_t *crc, size_t data_len)
{
uint16_t buf_crc = 0;

buf_crc = calculate_crc16(data, data_len, 0);
hexdump("calculated CRC", &buf_crc, CRC_LEN);

Expand Down
1 change: 1 addition & 0 deletions s96at/src/i2c_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
static uint32_t i2c_linux_open(void *ctx)
{
struct i2c_linux_ctx *ictx = ctx;

ictx->fd = open(I2C_DEVICE, O_RDWR);
if (ictx->fd < 0) {
logd("Couldn't open the device\n");
Expand Down
1 change: 1 addition & 0 deletions s96at/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ int at204_msg(struct io_interface *ioif, struct cmd_packet *p, void *resp_buf,
size_t size)
{
int ret = STATUS_EXEC_ERROR;

assert(resp_buf);

ret = at204_write2(ioif, p);
Expand Down
5 changes: 3 additions & 2 deletions s96at/src/s96at.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uint8_t s96at_init(enum s96at_device device, enum s96at_io_interface_type iface,

ret = register_io_interface(IO_I2C_LINUX, &desc->ioif);
if (ret != STATUS_OK)
return ret;
return ret;

ret = at204_open(desc->ioif);

Expand Down Expand Up @@ -109,6 +109,7 @@ uint8_t s96at_gen_digest(struct s96at_desc *desc, enum s96at_zone zone,
uint8_t slot, uint8_t *data)
{
size_t data_len;

if (data)
data_len = S96AT_GENDIG_INPUT_LEN;
else
Expand Down Expand Up @@ -246,7 +247,7 @@ uint8_t s96at_check_mac(struct s96at_desc *desc, enum s96at_mac_mode mode,
/* OtherData contains the parameters used for the MAC command */
check_mac_data[64] = OPCODE_MAC; /* Opcode */
check_mac_data[65] = mac_mode;
check_mac_data[66] = 0x00; /* Slot ID MSB */
check_mac_data[66] = 0x00; /* Slot ID MSB */
check_mac_data[67] = data->slot; /* Slot ID LSB */

if (data->otp) {
Expand Down
4 changes: 2 additions & 2 deletions s96at/src/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ int sha_apply_padding(uint8_t *buf, size_t buf_len, size_t msg_len, size_t *padd

memset(buf + msg_len, 0x00, buf_len - msg_len);
buf[msg_len] |= 0x80;
for (i = 0; i < SHA_PADDING_LENGTH_LEN; i++) {
for (i = 0; i < SHA_PADDING_LENGTH_LEN; i++)
buf[msg_len + padding_len + i] = ((msg_len * 8) >> (56 - i * 8)) & 0xff;
}

*padded_msg_len = msg_len + padding_len + SHA_PADDING_LENGTH_LEN;

return S96AT_STATUS_OK;
Expand Down

0 comments on commit 2ec8783

Please sign in to comment.