mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:
struct foo {
        int stuff;
        struct boo array[];
};
By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by
this change:
"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]
This issue was found with the help of Coccinelle.
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293 ("cxgb3/l2t: Fix undefined behaviour")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Link: https://lore.kernel.org/r/20200226212612.GA4663@embeddedor
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
		
	
			
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/******************************************************************************
 | 
						|
 * tpmif.h
 | 
						|
 *
 | 
						|
 * TPM I/O interface for Xen guest OSes, v2
 | 
						|
 *
 | 
						|
 * This file is in the public domain.
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
#ifndef __XEN_PUBLIC_IO_TPMIF_H__
 | 
						|
#define __XEN_PUBLIC_IO_TPMIF_H__
 | 
						|
 | 
						|
/*
 | 
						|
 * Xenbus state machine
 | 
						|
 *
 | 
						|
 * Device open:
 | 
						|
 *   1. Both ends start in XenbusStateInitialising
 | 
						|
 *   2. Backend transitions to InitWait (frontend does not wait on this step)
 | 
						|
 *   3. Frontend populates ring-ref, event-channel, feature-protocol-v2
 | 
						|
 *   4. Frontend transitions to Initialised
 | 
						|
 *   5. Backend maps grant and event channel, verifies feature-protocol-v2
 | 
						|
 *   6. Backend transitions to Connected
 | 
						|
 *   7. Frontend verifies feature-protocol-v2, transitions to Connected
 | 
						|
 *
 | 
						|
 * Device close:
 | 
						|
 *   1. State is changed to XenbusStateClosing
 | 
						|
 *   2. Frontend transitions to Closed
 | 
						|
 *   3. Backend unmaps grant and event, changes state to InitWait
 | 
						|
 */
 | 
						|
 | 
						|
enum vtpm_shared_page_state {
 | 
						|
	VTPM_STATE_IDLE,         /* no contents / vTPM idle / cancel complete */
 | 
						|
	VTPM_STATE_SUBMIT,       /* request ready / vTPM working */
 | 
						|
	VTPM_STATE_FINISH,       /* response ready / vTPM idle */
 | 
						|
	VTPM_STATE_CANCEL,       /* cancel requested / vTPM working */
 | 
						|
};
 | 
						|
/* The backend should only change state to IDLE or FINISH, while the
 | 
						|
 * frontend should only change to SUBMIT or CANCEL. */
 | 
						|
 | 
						|
 | 
						|
struct vtpm_shared_page {
 | 
						|
	uint32_t length;         /* request/response length in bytes */
 | 
						|
 | 
						|
	uint8_t state;           /* enum vtpm_shared_page_state */
 | 
						|
	uint8_t locality;        /* for the current request */
 | 
						|
	uint8_t pad;
 | 
						|
 | 
						|
	uint8_t nr_extra_pages;  /* extra pages for long packets; may be zero */
 | 
						|
	uint32_t extra_pages[]; /* grant IDs; length in nr_extra_pages */
 | 
						|
};
 | 
						|
 | 
						|
#endif
 |