Skip to content

Commit df4b37b

Browse files
Tomas Winklergregkh
authored andcommitted
mei: hbm: use sizeof of variable instead of struct type
There is a possibility of bug when variable type has changed but corresponding struct passed to the sizeof has not. Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Link: https://lore.kernel.org/r/20200723145927.882743-2-tomas.winkler@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e24ca92 commit df4b37b

1 file changed

Lines changed: 32 additions & 42 deletions

File tree

‎drivers/misc/mei/hbm.c‎

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
3-
* Copyright (c) 2003-2019, Intel Corporation. All rights reserved.
3+
* Copyright (c) 2003-2020, Intel Corporation. All rights reserved.
44
* Intel Management Engine Interface (Intel MEI) Linux driver
55
*/
66
#include <linux/export.h>
@@ -257,22 +257,21 @@ int mei_hbm_start_wait(struct mei_device *dev)
257257
int mei_hbm_start_req(struct mei_device *dev)
258258
{
259259
struct mei_msg_hdr mei_hdr;
260-
struct hbm_host_version_request start_req;
261-
const size_t len = sizeof(struct hbm_host_version_request);
260+
struct hbm_host_version_request req;
262261
int ret;
263262

264263
mei_hbm_reset(dev);
265264

266-
mei_hbm_hdr(&mei_hdr, len);
265+
mei_hbm_hdr(&mei_hdr, sizeof(req));
267266

268267
/* host start message */
269-
memset(&start_req, 0, len);
270-
start_req.hbm_cmd = HOST_START_REQ_CMD;
271-
start_req.host_version.major_version = HBM_MAJOR_VERSION;
272-
start_req.host_version.minor_version = HBM_MINOR_VERSION;
268+
memset(&req, 0, sizeof(req));
269+
req.hbm_cmd = HOST_START_REQ_CMD;
270+
req.host_version.major_version = HBM_MAJOR_VERSION;
271+
req.host_version.minor_version = HBM_MINOR_VERSION;
273272

274273
dev->hbm_state = MEI_HBM_IDLE;
275-
ret = mei_hbm_write_message(dev, &mei_hdr, &start_req);
274+
ret = mei_hbm_write_message(dev, &mei_hdr, &req);
276275
if (ret) {
277276
dev_err(dev->dev, "version message write failed: ret = %d\n",
278277
ret);
@@ -295,13 +294,12 @@ static int mei_hbm_dma_setup_req(struct mei_device *dev)
295294
{
296295
struct mei_msg_hdr mei_hdr;
297296
struct hbm_dma_setup_request req;
298-
const size_t len = sizeof(struct hbm_dma_setup_request);
299297
unsigned int i;
300298
int ret;
301299

302-
mei_hbm_hdr(&mei_hdr, len);
300+
mei_hbm_hdr(&mei_hdr, sizeof(req));
303301

304-
memset(&req, 0, len);
302+
memset(&req, 0, sizeof(req));
305303
req.hbm_cmd = MEI_HBM_DMA_SETUP_REQ_CMD;
306304
for (i = 0; i < DMA_DSCR_NUM; i++) {
307305
phys_addr_t paddr;
@@ -337,21 +335,19 @@ static int mei_hbm_dma_setup_req(struct mei_device *dev)
337335
static int mei_hbm_enum_clients_req(struct mei_device *dev)
338336
{
339337
struct mei_msg_hdr mei_hdr;
340-
struct hbm_host_enum_request enum_req;
341-
const size_t len = sizeof(struct hbm_host_enum_request);
338+
struct hbm_host_enum_request req;
342339
int ret;
343340

344341
/* enumerate clients */
345-
mei_hbm_hdr(&mei_hdr, len);
342+
mei_hbm_hdr(&mei_hdr, sizeof(req));
346343

347-
memset(&enum_req, 0, len);
348-
enum_req.hbm_cmd = HOST_ENUM_REQ_CMD;
349-
enum_req.flags |= dev->hbm_f_dc_supported ?
350-
MEI_HBM_ENUM_F_ALLOW_ADD : 0;
351-
enum_req.flags |= dev->hbm_f_ie_supported ?
344+
memset(&req, 0, sizeof(req));
345+
req.hbm_cmd = HOST_ENUM_REQ_CMD;
346+
req.flags |= dev->hbm_f_dc_supported ? MEI_HBM_ENUM_F_ALLOW_ADD : 0;
347+
req.flags |= dev->hbm_f_ie_supported ?
352348
MEI_HBM_ENUM_F_IMMEDIATE_ENUM : 0;
353349

354-
ret = mei_hbm_write_message(dev, &mei_hdr, &enum_req);
350+
ret = mei_hbm_write_message(dev, &mei_hdr, &req);
355351
if (ret) {
356352
dev_err(dev->dev, "enumeration request write failed: ret = %d.\n",
357353
ret);
@@ -380,7 +376,7 @@ static int mei_hbm_me_cl_add(struct mei_device *dev,
380376

381377
mei_me_cl_rm_by_uuid(dev, uuid);
382378

383-
me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
379+
me_cl = kzalloc(sizeof(*me_cl), GFP_KERNEL);
384380
if (!me_cl)
385381
return -ENOMEM;
386382

@@ -408,14 +404,13 @@ static int mei_hbm_add_cl_resp(struct mei_device *dev, u8 addr, u8 status)
408404
{
409405
struct mei_msg_hdr mei_hdr;
410406
struct hbm_add_client_response resp;
411-
const size_t len = sizeof(struct hbm_add_client_response);
412407
int ret;
413408

414409
dev_dbg(dev->dev, "adding client response\n");
415410

416-
mei_hbm_hdr(&mei_hdr, len);
411+
mei_hbm_hdr(&mei_hdr, sizeof(resp));
417412

418-
memset(&resp, 0, sizeof(struct hbm_add_client_response));
413+
memset(&resp, 0, sizeof(resp));
419414
resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD;
420415
resp.me_addr = addr;
421416
resp.status = status;
@@ -469,11 +464,10 @@ int mei_hbm_cl_notify_req(struct mei_device *dev,
469464

470465
struct mei_msg_hdr mei_hdr;
471466
struct hbm_notification_request req;
472-
const size_t len = sizeof(struct hbm_notification_request);
473467
int ret;
474468

475-
mei_hbm_hdr(&mei_hdr, len);
476-
mei_hbm_cl_hdr(cl, MEI_HBM_NOTIFY_REQ_CMD, &req, len);
469+
mei_hbm_hdr(&mei_hdr, sizeof(req));
470+
mei_hbm_cl_hdr(cl, MEI_HBM_NOTIFY_REQ_CMD, &req, sizeof(req));
477471

478472
req.start = start;
479473

@@ -580,8 +574,7 @@ static void mei_hbm_cl_notify(struct mei_device *dev,
580574
static int mei_hbm_prop_req(struct mei_device *dev, unsigned long start_idx)
581575
{
582576
struct mei_msg_hdr mei_hdr;
583-
struct hbm_props_request prop_req;
584-
const size_t len = sizeof(struct hbm_props_request);
577+
struct hbm_props_request req;
585578
unsigned long addr;
586579
int ret;
587580

@@ -591,18 +584,17 @@ static int mei_hbm_prop_req(struct mei_device *dev, unsigned long start_idx)
591584
if (addr == MEI_CLIENTS_MAX) {
592585
dev->hbm_state = MEI_HBM_STARTED;
593586
mei_host_client_init(dev);
594-
595587
return 0;
596588
}
597589

598-
mei_hbm_hdr(&mei_hdr, len);
590+
mei_hbm_hdr(&mei_hdr, sizeof(req));
599591

600-
memset(&prop_req, 0, sizeof(struct hbm_props_request));
592+
memset(&req, 0, sizeof(req));
601593

602-
prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
603-
prop_req.me_addr = addr;
594+
req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
595+
req.me_addr = addr;
604596

605-
ret = mei_hbm_write_message(dev, &mei_hdr, &prop_req);
597+
ret = mei_hbm_write_message(dev, &mei_hdr, &req);
606598
if (ret) {
607599
dev_err(dev->dev, "properties request write failed: ret = %d\n",
608600
ret);
@@ -628,15 +620,14 @@ int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd)
628620
{
629621
struct mei_msg_hdr mei_hdr;
630622
struct hbm_power_gate req;
631-
const size_t len = sizeof(struct hbm_power_gate);
632623
int ret;
633624

634625
if (!dev->hbm_f_pg_supported)
635626
return -EOPNOTSUPP;
636627

637-
mei_hbm_hdr(&mei_hdr, len);
628+
mei_hbm_hdr(&mei_hdr, sizeof(req));
638629

639-
memset(&req, 0, len);
630+
memset(&req, 0, sizeof(req));
640631
req.hbm_cmd = pg_cmd;
641632

642633
ret = mei_hbm_write_message(dev, &mei_hdr, &req);
@@ -657,11 +648,10 @@ static int mei_hbm_stop_req(struct mei_device *dev)
657648
{
658649
struct mei_msg_hdr mei_hdr;
659650
struct hbm_host_stop_request req;
660-
const size_t len = sizeof(struct hbm_host_stop_request);
661651

662-
mei_hbm_hdr(&mei_hdr, len);
652+
mei_hbm_hdr(&mei_hdr, sizeof(req));
663653

664-
memset(&req, 0, len);
654+
memset(&req, 0, sizeof(req));
665655
req.hbm_cmd = HOST_STOP_REQ_CMD;
666656
req.reason = DRIVER_STOP_REQUEST;
667657

0 commit comments

Comments
 (0)