Skip to content

Commit 92a643e

Browse files
andy-shevHans Verkuil
authored andcommitted
media: atomisp: Replace COMPILATION_ERROR_IF() by static_assert()
Replace COMPILATION_ERROR_IF() by static_assert(). Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 143fd8f commit 92a643e

File tree

10 files changed

+40
-65
lines changed

10 files changed

+40
-65
lines changed

drivers/staging/media/atomisp/pci/base/circbuf/interface/ia_css_circbuf_comm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef _IA_CSS_CIRCBUF_COMM_H
1717
#define _IA_CSS_CIRCBUF_COMM_H
1818

19+
#include <linux/build_bug.h>
20+
1921
#include <type_support.h> /* uint8_t, uint32_t */
2022

2123
#define IA_CSS_CIRCBUF_PADDING 1 /* The circular buffer is implemented in lock-less manner, wherein
@@ -45,6 +47,8 @@ struct ia_css_circbuf_desc_s {
4547
#define SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT \
4648
(4 * sizeof(uint8_t))
4749

50+
static_assert(sizeof(struct ia_css_circbuf_desc_s) == SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT);
51+
4852
/**
4953
* @brief Data structure for the circular buffer element.
5054
*/
@@ -56,4 +60,6 @@ struct ia_css_circbuf_elem_s {
5660
#define SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT \
5761
(sizeof(uint32_t))
5862

63+
static_assert(sizeof(struct ia_css_circbuf_elem_s) == SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT);
64+
5965
#endif /*_IA_CSS_CIRCBUF_COMM_H*/

drivers/staging/media/atomisp/pci/hive_isp_css_include/assert_support.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@
1616
#ifndef __ASSERT_SUPPORT_H_INCLUDED__
1717
#define __ASSERT_SUPPORT_H_INCLUDED__
1818

19-
/**
20-
* The following macro can help to test the size of a struct at compile
21-
* time rather than at run-time. It does not work for all compilers; see
22-
* below.
23-
*
24-
* Depending on the value of 'condition', the following macro is expanded to:
25-
* - condition==true:
26-
* an expression containing an array declaration with negative size,
27-
* usually resulting in a compilation error
28-
* - condition==false:
29-
* (void) 1; // C statement with no effect
30-
*
31-
* example:
32-
* COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != SIZE_OF_HOST_SP_QUEUES_STRUCT);
33-
*
34-
* verify that the macro indeed triggers a compilation error with your compiler:
35-
* COMPILATION_ERROR_IF( sizeof(struct host_sp_queues) != (sizeof(struct host_sp_queues)+1) );
36-
*
37-
* Not all compilers will trigger an error with this macro; use a search engine to search for
38-
* BUILD_BUG_ON to find other methods.
39-
*/
40-
#define COMPILATION_ERROR_IF(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
41-
4219
/* Compile time assertion */
4320
#ifndef CT_ASSERT
4421
#define CT_ASSERT(cnd) ((void)sizeof(char[(cnd) ? 1 : -1]))

drivers/staging/media/atomisp/pci/hive_isp_css_include/type_support.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333

3434
#define CHAR_BIT (8)
3535

36-
#include <linux/types.h>
37-
#include <linux/limits.h>
3836
#include <linux/errno.h>
37+
#include <linux/limits.h>
38+
#include <linux/types.h>
39+
3940
#define HOST_ADDRESS(x) (unsigned long)(x)
4041

4142
#endif /* __TYPE_SUPPORT_H_INCLUDED__ */

drivers/staging/media/atomisp/pci/ia_css_3a.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* This file contains types used for 3A statistics
2121
*/
2222

23+
#include <linux/build_bug.h>
24+
2325
#include <math_support.h>
2426
#include <type_support.h>
2527
#include "ia_css_types.h"
@@ -80,6 +82,8 @@ struct ia_css_isp_3a_statistics {
8082
SIZE_OF_IA_CSS_PTR + \
8183
4 * sizeof(uint32_t))
8284

85+
static_assert(sizeof(struct ia_css_isp_3a_statistics) == SIZE_OF_IA_CSS_ISP_3A_STATISTICS_STRUCT);
86+
8387
/* Map with host-side pointers to ISP-format statistics.
8488
* These pointers can either be copies of ISP data or memory mapped
8589
* ISP pointers.

drivers/staging/media/atomisp/pci/ia_css_dvs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* This file contains types for DVS statistics
2121
*/
2222

23+
#include <linux/build_bug.h>
24+
2325
#include <type_support.h>
2426
#include "ia_css_types.h"
2527
#include "ia_css_err.h"
@@ -55,6 +57,8 @@ struct ia_css_isp_skc_dvs_statistics;
5557
((3 * SIZE_OF_IA_CSS_PTR) + \
5658
(4 * sizeof(uint32_t)))
5759

60+
static_assert(sizeof(struct ia_css_isp_dvs_statistics) == SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT);
61+
5862
/* Map with host-side pointers to ISP-format statistics.
5963
* These pointers can either be copies of ISP data or memory mapped
6064
* ISP pointers.

drivers/staging/media/atomisp/pci/ia_css_metadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* This file contains structure for processing sensor metadata.
2121
*/
2222

23+
#include <linux/build_bug.h>
24+
2325
#include <type_support.h>
2426
#include "ia_css_types.h"
2527
#include "ia_css_stream_format.h"
@@ -50,6 +52,8 @@ struct ia_css_metadata {
5052

5153
#define SIZE_OF_IA_CSS_METADATA_STRUCT sizeof(struct ia_css_metadata)
5254

55+
static_assert(sizeof(struct ia_css_metadata) == SIZE_OF_IA_CSS_METADATA_STRUCT);
56+
5357
/* @brief Allocate a metadata buffer.
5458
* @param[in] metadata_info Metadata info struct, contains details on metadata buffers.
5559
* @return Pointer of metadata buffer or NULL (if error)

drivers/staging/media/atomisp/pci/ia_css_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ struct ia_css_state_memory_offsets;
8484
/* Virtual address within the CSS address space. */
8585
typedef u32 ia_css_ptr;
8686

87+
#define SIZE_OF_IA_CSS_PTR sizeof(uint32_t)
88+
8789
/* Generic resolution structure.
8890
*/
8991
struct ia_css_resolution {

drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl_comm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef __IA_CSS_SPCTRL_COMM_H__
1717
#define __IA_CSS_SPCTRL_COMM_H__
1818

19+
#include <linux/build_bug.h>
20+
1921
#include <type_support.h>
2022

2123
/* state of SP */
@@ -43,4 +45,6 @@ struct ia_css_sp_init_dmem_cfg {
4345
(4 * sizeof(uint32_t)) + \
4446
(1 * sizeof(sp_ID_t))
4547

48+
static_assert(sizeof(struct ia_css_sp_init_dmem_cfg) == SIZE_OF_IA_CSS_SP_INIT_DMEM_CFG_STRUCT);
49+
4650
#endif /* __IA_CSS_SPCTRL_COMM_H__ */

drivers/staging/media/atomisp/pci/sh_css.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,47 +1345,9 @@ ia_css_init(struct device *dev, const struct ia_css_env *env,
13451345
{
13461346
int err;
13471347
ia_css_spctrl_cfg spctrl_cfg;
1348-
13491348
void (*flush_func)(struct ia_css_acc_fw *fw);
13501349
hrt_data select, enable;
13511350

1352-
/*
1353-
* The C99 standard does not specify the exact object representation of structs;
1354-
* the representation is compiler dependent.
1355-
*
1356-
* The structs that are communicated between host and SP/ISP should have the
1357-
* exact same object representation. The compiler that is used to compile the
1358-
* firmware is hivecc.
1359-
*
1360-
* To check if a different compiler, used to compile a host application, uses
1361-
* another object representation, macros are defined specifying the size of
1362-
* the structs as expected by the firmware.
1363-
*
1364-
* A host application shall verify that a sizeof( ) of the struct is equal to
1365-
* the SIZE_OF_XXX macro of the corresponding struct. If they are not
1366-
* equal, functionality will break.
1367-
*/
1368-
1369-
/* Check struct sh_css_ddr_address_map */
1370-
COMPILATION_ERROR_IF(sizeof(struct sh_css_ddr_address_map) != SIZE_OF_SH_CSS_DDR_ADDRESS_MAP_STRUCT);
1371-
/* Check struct host_sp_queues */
1372-
COMPILATION_ERROR_IF(sizeof(struct host_sp_queues) != SIZE_OF_HOST_SP_QUEUES_STRUCT);
1373-
COMPILATION_ERROR_IF(sizeof(struct ia_css_circbuf_desc_s) != SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT);
1374-
COMPILATION_ERROR_IF(sizeof(struct ia_css_circbuf_elem_s) != SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT);
1375-
1376-
/* Check struct host_sp_communication */
1377-
COMPILATION_ERROR_IF(sizeof(struct host_sp_communication) != SIZE_OF_HOST_SP_COMMUNICATION_STRUCT);
1378-
COMPILATION_ERROR_IF(sizeof(struct sh_css_event_irq_mask) != SIZE_OF_SH_CSS_EVENT_IRQ_MASK_STRUCT);
1379-
1380-
/* Check struct sh_css_hmm_buffer */
1381-
COMPILATION_ERROR_IF(sizeof(struct sh_css_hmm_buffer) != SIZE_OF_SH_CSS_HMM_BUFFER_STRUCT);
1382-
COMPILATION_ERROR_IF(sizeof(struct ia_css_isp_3a_statistics) != SIZE_OF_IA_CSS_ISP_3A_STATISTICS_STRUCT);
1383-
COMPILATION_ERROR_IF(sizeof(struct ia_css_isp_dvs_statistics) != SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT);
1384-
COMPILATION_ERROR_IF(sizeof(struct ia_css_metadata) != SIZE_OF_IA_CSS_METADATA_STRUCT);
1385-
1386-
/* Check struct ia_css_init_dmem_cfg */
1387-
COMPILATION_ERROR_IF(sizeof(struct ia_css_sp_init_dmem_cfg) != SIZE_OF_IA_CSS_SP_INIT_DMEM_CFG_STRUCT);
1388-
13891351
if (!env)
13901352
return -EINVAL;
13911353

drivers/staging/media/atomisp/pci/sh_css_internal.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#ifndef _SH_CSS_INTERNAL_H_
1717
#define _SH_CSS_INTERNAL_H_
1818

19+
#include <linux/build_bug.h>
20+
#include <linux/stdarg.h>
21+
1922
#include <system_global.h>
2023
#include <math_support.h>
2124
#include <type_support.h>
2225
#include <platform_support.h>
23-
#include <linux/stdarg.h>
2426

2527
#include "input_formatter.h"
2628
#include "input_system.h"
@@ -104,7 +106,6 @@
104106
*/
105107
#define CALC_ALIGNMENT_MEMBER(x, y) (CEIL_MUL(x, y) - x)
106108
#define SIZE_OF_HRT_VADDRESS sizeof(hive_uint32)
107-
#define SIZE_OF_IA_CSS_PTR sizeof(uint32_t)
108109

109110
/* Number of SP's */
110111
#define NUM_OF_SPS 1
@@ -202,6 +203,8 @@ struct sh_css_ddr_address_map {
202203
(SH_CSS_MAX_STAGES * IA_CSS_NUM_MEMORIES * SIZE_OF_HRT_VADDRESS) + \
203204
(16 * SIZE_OF_HRT_VADDRESS))
204205

206+
static_assert(sizeof(struct sh_css_ddr_address_map) == SIZE_OF_SH_CSS_DDR_ADDRESS_MAP_STRUCT);
207+
205208
/* xmem address map allocation per pipeline */
206209
struct sh_css_ddr_address_map_size {
207210
size_t isp_param;
@@ -705,6 +708,8 @@ struct sh_css_hmm_buffer {
705708
SIZE_OF_IA_CSS_CLOCK_TICK_STRUCT + \
706709
CALC_ALIGNMENT_MEMBER(SIZE_OF_IA_CSS_CLOCK_TICK_STRUCT, 8))
707710

711+
static_assert(sizeof(struct sh_css_hmm_buffer) == SIZE_OF_SH_CSS_HMM_BUFFER_STRUCT);
712+
708713
enum sh_css_queue_type {
709714
sh_css_invalid_queue_type = -1,
710715
sh_css_host2sp_buffer_queue,
@@ -724,6 +729,8 @@ struct sh_css_event_irq_mask {
724729
#define SIZE_OF_SH_CSS_EVENT_IRQ_MASK_STRUCT \
725730
(2 * sizeof(uint16_t))
726731

732+
static_assert(sizeof(struct sh_css_event_irq_mask) == SIZE_OF_SH_CSS_EVENT_IRQ_MASK_STRUCT);
733+
727734
struct host_sp_communication {
728735
/*
729736
* Don't use enum host2sp_commands, because the sizeof an enum is
@@ -761,6 +768,8 @@ struct host_sp_communication {
761768
((3 + N_CSI_PORTS) * sizeof(uint32_t)) + \
762769
(NR_OF_PIPELINES * SIZE_OF_SH_CSS_EVENT_IRQ_MASK_STRUCT))
763770

771+
static_assert(sizeof(struct host_sp_communication) == SIZE_OF_HOST_SP_COMMUNICATION_STRUCT);
772+
764773
struct host_sp_queues {
765774
/*
766775
* Queues for the dynamic frame information,
@@ -831,6 +840,8 @@ struct host_sp_queues {
831840
#define SIZE_OF_HOST_SP_QUEUES_STRUCT \
832841
(SIZE_OF_QUEUES_ELEMS + SIZE_OF_QUEUES_DESC)
833842

843+
static_assert(sizeof(struct host_sp_queues) == SIZE_OF_HOST_SP_QUEUES_STRUCT);
844+
834845
extern int __printf(1, 0) (*sh_css_printf)(const char *fmt, va_list args);
835846

836847
static inline void __printf(1, 2) sh_css_print(const char *fmt, ...)

0 commit comments

Comments
 (0)