Skip to content

Commit 8368148

Browse files
committed
driver: generate_commands: only generate variables when we need them
Otherwise we might declare "dev" and "ret" but never end up using them.
1 parent bb68b31 commit 8368148

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

driver.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,20 @@ def generate_reset(p: Panel) -> str:
124124

125125

126126
def generate_commands(p: Panel, options: Options, cmd_name: str) -> str:
127+
cmd = p.cmds[cmd_name]
128+
127129
s = f'''\
128130
static int {p.short_id}_{cmd_name}(struct {p.short_id} *ctx)
129131
{{
130-
struct mipi_dsi_device *dsi = ctx->dsi;
131-
struct device *dev = &dsi->dev;
132-
int ret;
133132
'''
134-
cmd = p.cmds[cmd_name]
133+
variables = ['struct mipi_dsi_device *dsi = ctx->dsi']
134+
if '(dev, ' in cmd.generated:
135+
variables.append('struct device *dev = &dsi->dev')
136+
if 'ret = ' in cmd.generated:
137+
variables.append('int ret')
138+
139+
for v in variables:
140+
s += f'\t{v};\n'
135141

136142
if p.cmds['on'].state != p.cmds['off'].state:
137143
if cmd.state == CommandSequence.State.LP_MODE:

0 commit comments

Comments
 (0)