forked from mirrors/linux
		
	tools: ynl-gen: don't declare loop iterator in place
The codegen tries to follow the "old" C style and declare loop iterators at the start of the block / function. Only nested request handling breaks this style, so adjust it. Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/20250414211851.602096-2-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
		
							parent
							
								
									00ffb3724c
								
							
						
					
					
						commit
						4d07bbf2d4
					
				
					 1 changed files with 21 additions and 4 deletions
				
			
		|  | @ -654,10 +654,10 @@ class TypeMultiAttr(Type): | |||
|     def attr_put(self, ri, var): | ||||
|         if self.attr['type'] in scalars: | ||||
|             put_type = self.type | ||||
|             ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)") | ||||
|             ri.cw.p(f"for (i = 0; i < {var}->n_{self.c_name}; i++)") | ||||
|             ri.cw.p(f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);") | ||||
|         elif 'type' not in self.attr or self.attr['type'] == 'nest': | ||||
|             ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)") | ||||
|             ri.cw.p(f"for (i = 0; i < {var}->n_{self.c_name}; i++)") | ||||
|             self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " + | ||||
|                                 f"{self.enum_name}, &{var}->{self.c_name}[i])") | ||||
|         else: | ||||
|  | @ -1644,11 +1644,23 @@ def put_req_nested_prototype(ri, struct, suffix=';'): | |||
| 
 | ||||
| 
 | ||||
| def put_req_nested(ri, struct): | ||||
|     local_vars = [] | ||||
|     init_lines = [] | ||||
| 
 | ||||
|     local_vars.append('struct nlattr *nest;') | ||||
|     init_lines.append("nest = ynl_attr_nest_start(nlh, attr_type);") | ||||
| 
 | ||||
|     for _, arg in struct.member_list(): | ||||
|         if arg.presence_type() == 'count': | ||||
|             local_vars.append('unsigned int i;') | ||||
|             break | ||||
| 
 | ||||
|     put_req_nested_prototype(ri, struct, suffix='') | ||||
|     ri.cw.block_start() | ||||
|     ri.cw.write_func_lvar('struct nlattr *nest;') | ||||
|     ri.cw.write_func_lvar(local_vars) | ||||
| 
 | ||||
|     ri.cw.p("nest = ynl_attr_nest_start(nlh, attr_type);") | ||||
|     for line in init_lines: | ||||
|         ri.cw.p(line) | ||||
| 
 | ||||
|     for _, arg in struct.member_list(): | ||||
|         arg.attr_put(ri, "obj") | ||||
|  | @ -1850,6 +1862,11 @@ def print_req(ri): | |||
|         local_vars += ['size_t hdr_len;', | ||||
|                        'void *hdr;'] | ||||
| 
 | ||||
|     for _, attr in ri.struct["request"].member_list(): | ||||
|         if attr.presence_type() == 'count': | ||||
|             local_vars += ['unsigned int i;'] | ||||
|             break | ||||
| 
 | ||||
|     print_prototype(ri, direction, terminate=False) | ||||
|     ri.cw.block_start() | ||||
|     ri.cw.write_func_lvar(local_vars) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Jakub Kicinski
						Jakub Kicinski